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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 case with updating inside

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 @TypeArray
WHEN 1 THEN UPDATE Table1 SET [Id] = @Id WHERE Sale = @Sale
WHEN 2 THEN UPDATE Table2 SET [Id] = @Id WHERE Sale = @Sale
END

I 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 @TypeArray
WHEN 1 THEN exec StoredProcedure1
WHEN 2 THEN exec StoredProcedure2
END

Anything 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.



Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-04-17 : 08:37:58
You can do something like this also.

DECLARE @TypeArray INTEGER
DECLARE @SQL NVARCHAR(255)

SET @TypeArray = 1

SELECT @SQL = CASE @TypeArray
WHEN 1 THEN 'sp_help'
WHEN 2 THEN 'sp_who'
END

EXEC @SQL

Go to Top of Page
   

- Advertisement -