Try a CASE statement... Might work for you.
-----Original Message-----
From: Bruce, Rodney S Mr CTR USA AMC [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 02, 2007 10:02 AM
To: SQL
Subject: RE: Conditional logic in SQL SPs
Maya,
Thanks for the reply.
Yep, I know about the IF....ELSE...
But I need more conditions:
IF @Myvar = 1
ELSE IF @Myvar = 2
ELSE
for anything else
With just the IF....ELSE...
The only way I can get it to work is to add a control var
@control = false
IF @Myvar = 1
@control = true
IF @Myvar = 2
@control = true
IF @control = false
Do this
Just wondering if the IF....ELSE IF.....ELSE was possible.
Or if I am missing a better way.
Thanks
Rodney
-----Original Message-----
From: Maya Tulchinsky [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 02, 2007 5:03 AM
To: SQL
Subject: Re: Conditional logic in SQL SPs
You can use IF - ELSE
IF Boolean_expression
BEGIN
{ sql_statement | statement_block }
END
ELSE
BEGIN
{ sql_statement | statement_block }
END
http://msdn2.microsoft.com/en-us/library/aa258850(sql.80).aspx
Hope this helps
Maya
"Bruce, Rodney S Mr CTR USA AMC" <[EMAIL PROTECTED]> wrote:
Hi,
Does SQL (MS SQL 2005) SPs allow/have: IF ELSEIF ELSE, structure?
IF something = 1
ELSEIF something = 2
ELSE something = anything else
OR
a SWITCH/CASE?
I can find examples for inside a query
Select f1,f2
Case f1
WHERE '1' then this
WHERE '2' then something else
But can not find an example for:
CASE @MyVar
WHERE '1' then
BEGIN
Select *
From Mytable
End
Where '2' then
Begin
Select *
From Mytable2
End
Any help would be appreciated.
Thanks
Rodney
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Download the latest ColdFusion 8 utilities including Report Builder,
plug-ins for Eclipse and Dreamweaver updates.
http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta
Archive: http://www.houseoffusion.com/groups/SQL/message.cfm/messageid:2958
Subscription: http://www.houseoffusion.com/groups/SQL/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.6