Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-01-18 : 10:41:58
|
| Brian writes "I have been racking my brains to figure a more efficient way to test multiple conditions in a stored procedure under MS SQL 7.0. Idealy it would be something similar to SWITCH..CASE..CASE ELSE. I am currently using multiple IF..BEGIN..END statements, and though it performs well enough I just think there has to be a cleaner way.ThanksBrian Dugan" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-01-18 : 12:13:20
|
| The CASE statement exists in SQL Server, but it is not a control-of-flow statement like SWITCH, it's more like a function. It works something like this:SELECT FirstName, LastName, CASE Sex WHEN 'M' THEN 'Mr.' WHEN 'F' THEN 'Ms.'ELSE '' END AS SalutationFROM myTableIt's important to remember that CASE returns a value. If you need to change the actions based on a condition then CASE won't work for you; you'll have to stick with multiple IF statements.Take a look here for more info, also check Books Online for CASE:http://www.sqlteam.com/item.asp?ItemID=922http://www.sqlteam.com/redir.asp?ItemID=3223http://www.sqlteam.com/redir.asp?ItemID=2212 |
 |
|
|
|
|
|