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 2008 Forums
 Transact-SQL (2008)
 Stored Procedure with a case statement

Author  Topic 

ben_53
Yak Posting Veteran

67 Posts

Posted - 2011-07-18 : 18:10:24
Hi Reader,

I want to make a structure of a stored procedure that will generate/update IDs for 2 columns of TableDriver. NOTE that TableDriver is further unionall of 6 other tables and DriverTable has a column named TableSource with possible values of Table1, Table2 .... Table6 indicating the data which table it belongs to.
Also, It has another column named action which can have either insert or update values. It has different business logic depending upon insert/update.

Okay so I was creating the stored procedure like this :

Create Procedure ABC_SP
@ID1 = varchar(20)
@ID2 = varchar(20)
AS
Select sysID, tableSource = Case When 'Table1'
then ( Action = case
when insert then '.......'
else '.....'
end)

when 'Table2
then ( Action = case
when insert then '.......'
else '.....'
end)
..... and so on

end

Would It work ? My queries are very long.
Please help me designing the structure.



webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-19 : 02:49:06
Please be a bit more specific on what you are trying to do.
What should be the result of your select?

edit: best is to give us table structure, example data and wanted result.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -