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 - 2003-04-17 : 07:40:58
|
leon writes "Simply put...I want to know how to do this type of update based on a parameter passed...it will do a perticular update to a given table...as below.SELECT CASE @TypeArrayWHEN 1 THEN UPDATE Table1 SET [Id] = @Id WHERE Sale = @Sale WHEN 2 THEN UPDATE Table2 SET [Id] = @Id WHERE Sale = @Sale ENDI get thwe feeling that all the examples I have seen tend to use for assigning the value to something instead of actually doing something or executing a stored procedure...SELECT CASE @TypeArrayWHEN 1 THEN exec StoredProcedure1 WHEN 2 THEN exec StoredProcedure2ENDAnything would be helpful." |
|
Andraax
Aged Yak Warrior
790 Posts |
Posted - 2003-04-17 : 08:29:47
|
Hello Leon!CASE does not work that way in TSQL. You'll have to use IF instead. |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2003-04-17 : 08:37:58
|
You can do something like this also.DECLARE @TypeArray INTEGERDECLARE @SQL NVARCHAR(255)SET @TypeArray = 1SELECT @SQL = CASE @TypeArrayWHEN 1 THEN 'sp_help'WHEN 2 THEN 'sp_who'ENDEXEC @SQL |
|
|
|
|
|