472,126 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

Valid T-SQL syntax?

DFS
Version 1:
--------------------------------
If Condition = A
UPDATE query 1
UPDATE query 2
ELSE IF Condition = B
UPDATE query

Version 2:
--------------------------------
If Condition = A
BEGIN
UPDATE query 1
UPDATE query 2
END
ELSE IF Condition = B
BEGIN
UPDATE query
END
Or are they functionally equivalent?

Thanks


Jul 20 '05 #1
2 9586

"DFS" <no****@nospam.com> wrote in message
news:10*************@corp.supernews.com...
Version 1:
--------------------------------
If Condition = A
UPDATE query 1
UPDATE query 2
ELSE IF Condition = B
UPDATE query

Version 2:
--------------------------------
If Condition = A
BEGIN
UPDATE query 1
UPDATE query 2
END
ELSE IF Condition = B
BEGIN
UPDATE query
END
Or are they functionally equivalent?

Thanks


See the Books Online entry for IF ... ELSE ... Version 1 is not valid
syntax - IF must be followed by a single SQL statement, or by a block of
statements enclosed in BEGIN ... END. Version 2, on the other hand, is
correct. Try it yourself in Query Analyzer, and you should get a syntax
error using version 1.

Simon
Jul 20 '05 #2
DFS

"Simon Hayes" <sq*@hayes.ch> wrote in message
news:40**********@news.bluewin.ch...

"DFS" <no****@nospam.com> wrote in message
news:10*************@corp.supernews.com...
Version 1:
--------------------------------
If Condition = A
UPDATE query 1
UPDATE query 2
ELSE IF Condition = B
UPDATE query

Version 2:
--------------------------------
If Condition = A
BEGIN
UPDATE query 1
UPDATE query 2
END
ELSE IF Condition = B
BEGIN
UPDATE query
END
Or are they functionally equivalent?

Thanks


See the Books Online entry for IF ... ELSE ... Version 1 is not valid
syntax - IF must be followed by a single SQL statement, or by a block of
statements enclosed in BEGIN ... END. Version 2, on the other hand, is
correct. Try it yourself in Query Analyzer, and you should get a syntax
error using version 1.

Simon


Thanks. Yes, I tried it last night and it's just as you say.


Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Shyamal Prasad | last post: by
1 post views Thread by Anna | last post: by
1 post views Thread by Beau Hayes | last post: by
7 posts views Thread by JR | last post: by
23 posts views Thread by James Aguilar | last post: by
3 posts views Thread by Chris | last post: by
2 posts views Thread by Arpan | last post: by
10 posts views Thread by SpreadTooThin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.