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 |
|
Superman
Starting Member
2 Posts |
Posted - 2003-04-30 : 15:05:05
|
| Is there a way to write this in a Case statement or is it better as it is? In VB, "CASE" would be use rather than "IF" when there are more than 2 choices. Is that the same in SQL Server?CREATE PROCEDURE [XMLZ] @ReportType CHAR(25), ASIF @ReportType='1' BEGINEND IF @ReportType='2' BEGINEND IF @ReportType='3' BEGINEND |
|
|
JustinBigelow
SQL Gigolo
1157 Posts |
Posted - 2003-04-30 : 15:08:38
|
Syntax wise there is nothing wrong with your procedure (except for the comma after the parameter ) but you are right that a case statement would be cleaner. I'd suggest looking up CASE in Books On Line for a rundown of the command and examples.Justin"Blue canary in the outlet by the light switch / Who watches over you." |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-04-30 : 15:09:03
|
| in SQL, CASE is actually a function (I call it a "construct") not a control-of-flow statement.That is, it just returns a value -- doesn't actually DO anything or control what happens.Set @a = CASE WHEN @a = 1 then @a + 1 ELSE @b ENDis equivalent to:IF @a = 1 SET @a = @a + 1 ELSE Set @a = @bThe VB CASE statement is very different than the SQL CASE Expression. It's closer to IIF() if you've seen that function in VBA.What you wrote is looks fine to me.- Jeff |
 |
|
|
Superman
Starting Member
2 Posts |
Posted - 2003-04-30 : 16:20:44
|
| Thanks for clearing that up! |
 |
|
|
|
|
|