Click here to Skip to main content
15,892,804 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my requirements based on the param i need to get the Procedure name.
So i wish to use Switch statement rather than using of multiple if statements.
(I don't want to prepare a table with paramid,proc name.)
Please let me know SQL supports switch statement if yes what is the syntax.

Thank you.
Posted
Comments
Patrice T 8-Sep-15 6:14am    
What about doing basic research by yourself and look at documentation ?

Hi,

MSSQL's equivalent of switch is it's Case statement.

It's usage is described in the documentation for: CASE (Transact-SQL)[^]

... hope it helps.
 
Share this answer
 
You can use CASE in sql server as per your need.
for example :
SQL
DECLARE @TestVal int
SET @TestVal = 3
SELECT
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END

Please go to the link to learn more about case CASE statement in SQL server[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900