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 |
|
cidmi.dovic
Yak Posting Veteran
53 Posts |
Posted - 2007-04-11 : 13:09:34
|
| Hi,I'm a c# programmer and I want to know if is there anything similar to the switch sentence in TSQL. I mean, I pass a int to a Stored Procedure and with this value I have to do differents updates in a record. I can use four if..then but it's little elegant ;-)Thanks. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-11 : 13:22:39
|
| What are you trying to accomplish in the stored procedure?If you can, please post code here.Peter LarssonHelsingborg, Sweden |
 |
|
|
cidmi.dovic
Yak Posting Veteran
53 Posts |
Posted - 2007-04-11 : 13:30:38
|
| For example:ALTER PROCEDURE sample @status INTAS IF @Status = 0 UPDATE sample_table SET s_f = update_value ELSE IF @Status = 1 UPDATE sample_table SET s_f = update_value, s_f1 = update_value2 ELSE IF @Status = 2 ....And so on.My question is , Can I make something similar to this?ALTER PROCEDURE sample @status INTAS switch(@status) CASE 0: UPDATE sample_table SET s_f = update_value CASE 1: UPDATE sample_table SET s_f = update_value, s_f1 = update_value2 ... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-11 : 13:36:01
|
| The short answer is "No".Peter LarssonHelsingborg, Sweden |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-04-11 : 14:32:19
|
| [code]ALTER PROCEDURE sample@status INTASUPDATE sample_table SET s_f = CASE WHEN @status IN (0, 1) THEN update_value ELSE s_f END, s_f1 = CASE WHEN @status IN (1) THEN update_value2 ELSE s_f1 END[/code]Kristen |
 |
|
|
|
|
|