Use of switch and while loop in sql server 2005
How to use Switch case in Sql server 2005, pls give me some example of swich and while loop in sql server 2005
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jan 10, 2012, 11:06 PM
In SQL server, there is no swich case.
but you may use case - when with select statement.
example.
Declare @ListPrice as int.
// set value of @ListPrice
SELECT CASE
WHEN ListPrice = 0 THEN 'Mfg item - not for resale'
WHEN ListPrice < 50 THEN 'Under $50'
WHEN ListPrice >= 50 and ListPrice < 250 THEN 'Under $250'
WHEN ListPrice >= 250 and ListPrice < 1000 THEN 'Under $1000'
ELSE 'Over $1000'
END
hope this help.
VulpesPosted Jan 10, 2012, 4:29 AM
http://msdn.microsoft.com/en-us/library/ms181765(SQL.90).aspx
http://msdn.microsoft.com/en-us/library/ms178642(SQL.90).aspx
Notice that it's just called a CASE expression, not SWITCH CASE.