VB like CASE Statement construct in SQL? | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

VB like CASE Statement construct in SQL?

Without having to do a large IF statement can I do something like the following in a SQL Stored proceedure. CREATE PROCEDURE [GetPendingDeliveries] @Sortby as char(32) =’aao’ AS SET NOCOUNT ON
**** VBish code starts *************
select CASE @SortBy
case ‘tvstn’
select * from digitalspots.dbo.v_pendingspots order by tvstn
case ‘adv’
select * from digitalspots.dbo.v_pendingspots order by advertiser
else
select * from digitalspots.dbo.v_pendingspots order by aao
end select
Thanks
Yes. This article is all about that http://www.winnetmag.com/SQLServer/Article/ArticleID/16495/16495.html] Nathan H.O.
Moderator
SQL-Server-Performance.com
]]>