November 8, 2012 at 5:11 pm
How do I write multiple IF statements but only one BEGIN block? In other words, I would love to have an OR statement between the IF statements but I know that is not possible. If someone can shed some light on what I am doing wrong.
IF EXISTS <CODE>
IF EXISTS <CODE>
IF EXISTS <CODE>
BEGIN
<CODE>
END
ELSE
<CODE>
November 8, 2012 at 5:13 pm
SQLSeTTeR (11/8/2012)
How do I write multiple IF statements but only one BEGIN block? In other words, I would love to have an OR statement between the IF statements but I know that is not possible. If someone can shed some light on what I am doing wrong.IF EXISTS <CODE>
IF EXISTS <CODE>
IF EXISTS <CODE>
BEGIN
<CODE>
END
ELSE
<CODE>
Not sure I understand? This should work fine:
IF EXISTS (SELECT 1 FROM table1 WHERE id = @a)
OR EXISTS (SELECT 1 FROM table2 WHERE id = @a)
OR EXISTS (SELECT 1 FROM table3 WHERE id = @a)
BEGIN
-- Some Code
END
What trouble are you running into?
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
November 8, 2012 at 5:14 pm
That is what I'm looking for. Not thinking. Thank you very much.
November 8, 2012 at 5:19 pm
That did it, Thanks again.
November 8, 2012 at 5:30 pm
SQLSeTTeR (11/8/2012)
That is what I'm looking for. Not thinking. Thank you very much.
Heheh, I've had those days. 😀 Glad I could help.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply