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 |
|
John T.
Posting Yak Master
112 Posts |
Posted - 2003-04-21 : 17:17:25
|
| I want to be able to pass a variable to my sproc and based upon its value, assign other values to declared variables to insert to a table.The variable is @AbbSelI try :CASE @AbbSel WHEN 'V'THEN SET @game = [Vis] + 'vs.' [Home] SET @sport = 'MLB'WHEN 'H'THEN SET @game = [Vis] + 'vs.' [Home] SET sport = 'MLB'END CASE[Vis] and [Home] are field values from a selected table. I simply take some of those values and plan to insert to a different table.I tried with IF..Then but seem to run into a problem there. I have tried quite a few iterations. Yesterday, I learned that you have to have a matching Else with an If. My If expression by itself would not work without using an Else. But I have 4 cases to evaluate here and no idea how to do it with SQL. Somebody educate me please.Appreciate it.John |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-04-21 : 17:59:26
|
| if @AbbSel = 'V' beginselect @game = [Vis] + 'vs.' + [Home] , @sport = 'MLB' from tblendelse if @AbbSel = 'H' begin select @game = [Vis] + 'vs.' + [Home] , sport = 'MLB' from tblendorselect @game = case @AbbSel when 'V' then [Vis] + 'vs.' + [Home]when 'H' then [Vis] + 'vs.' [Home]end, @sport = case @AbbSel when 'V' then 'MLB' when 'H' then 'MLB' endfrom tbl==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
John T.
Posting Yak Master
112 Posts |
Posted - 2003-04-21 : 19:37:31
|
| Thanks very much. A great help. |
 |
|
|
|
|
|