April 1, 2013 at 8:20 pm
Comments posted to this topic are about the item TRY...CATCH
___________________________________________________________________
If I can answer a question then anyone can answer it..trying to reverse the logic.. :hehe:
April 1, 2013 at 10:58 pm
Good one. New thing come to know.
Thank. Keep it up !!! 🙂
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
April 1, 2013 at 11:36 pm
Good question :-):-)
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 1, 2013 at 11:43 pm
Nice....
April 2, 2013 at 1:39 am
Good question, but the explanation falls a bit short. I was very disappointed when I first saw this behaviour. A semicolon is a statement terminator and should be used after every statement - but apparently, END TRY is not considered a statement by this logic. So the semicolon after END TRY is not interpreted as terminating the END TRY, but as terminating a dummy, zero-length statement. (They exist. Try typing a bunch of semicolons and hit execute - it will complete without errors).
In short - just after I had learned myself to consistently semicolon-terminate every statement, I now have to leanr myself NOT to do that for at least one statement (END TRY).
April 2, 2013 at 2:18 am
I selected the syntax error option but not for the reason stated. The question states SQL 2005 and higher, but THROW evidently makes its appearance with SQL 2012, so is invalid syntax is the right answer for 2005, 2008, 2008 R2, eh?
So, another case of "it depends".
April 2, 2013 at 2:41 am
This was removed by the editor as SPAM
April 2, 2013 at 6:00 am
Hugo Kornelis (4/2/2013)
Good question, but the explanation falls a bit short. I was very disappointed when I first saw this behaviour. A semicolon is a statement terminator and should be used after every statement - but apparently, END TRY is not considered a statement by this logic. So the semicolon after END TRY is not interpreted as terminating the END TRY, but as terminating a dummy, zero-length statement. (They exist. Try typing a bunch of semicolons and hit execute - it will complete without errors).In short - just after I had learned myself to consistently semicolon-terminate every statement, I now have to leanr myself NOT to do that for at least one statement (END TRY).
Thanks for clearing that up Hugo - I was scratching my head trying to work out where the extra statement between the try and the catch was.
April 2, 2013 at 6:04 am
+1... nice question to learn about TRY-Catch....
Learn new things every where
Manik
Manik
You cannot get to the top by sitting on your bottom.
April 2, 2013 at 6:07 am
Hugo Kornelis (4/2/2013)
Good question, but the explanation falls a bit short. I was very disappointed when I first saw this behaviour. A semicolon is a statement terminator and should be used after every statement - but apparently, END TRY is not considered a statement by this logic. So the semicolon after END TRY is not interpreted as terminating the END TRY, but as terminating a dummy, zero-length statement. (They exist. Try typing a bunch of semicolons and hit execute - it will complete without errors).In short - just after I had learned myself to consistently semicolon-terminate every statement, I now have to leanr myself NOT to do that for at least one statement (END TRY).
+1... nice....
Manik
You cannot get to the top by sitting on your bottom.
April 2, 2013 at 7:09 am
Definately learned something about the odd behaviour of SQL Server...
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
April 2, 2013 at 7:39 am
Stewart "Arturius" Campbell (4/2/2013)
Hugo Kornelis (4/2/2013)
Good question, but the explanation falls a bit short. I was very disappointed when I first saw this behaviour. A semicolon is a statement terminator and should be used after every statement - but apparently, END TRY is not considered a statement by this logic. So the semicolon after END TRY is not interpreted as terminating the END TRY, but as terminating a dummy, zero-length statement. (They exist. Try typing a bunch of semicolons and hit execute - it will complete without errors).In short - just after I had learned myself to consistently semicolon-terminate every statement, I now have to leanr myself NOT to do that for at least one statement (END TRY).
+1
what a gotcha...
+1. The thought of this weird behavior happening never even crossed my mind. Great question.
April 2, 2013 at 7:49 am
Hugo Kornelis (4/2/2013)
Good question, but the explanation falls a bit short. I was very disappointed when I first saw this behaviour. A semicolon is a statement terminator and should be used after every statement - but apparently, END TRY is not considered a statement by this logic. So the semicolon after END TRY is not interpreted as terminating the END TRY, but as terminating a dummy, zero-length statement. (They exist. Try typing a bunch of semicolons and hit execute - it will complete without errors).In short - just after I had learned myself to consistently semicolon-terminate every statement, I now have to leanr myself NOT to do that for at least one statement (END TRY).
+1..
Thanks Hugo for the explanation and helping me out on this one. This is my first Qotd and I had this whole zero length statement explanation set up but for some reason got mixed up and posted the condensed version. As usual you are there to help out all the newbies like me.. Your posts are always very insightful..
Go Hugo !!! 😀
___________________________________________________________________
If I can answer a question then anyone can answer it..trying to reverse the logic.. :hehe:
April 2, 2013 at 7:53 am
Good question, but I agree that SQL is not easy when it comes to the use of the semi-colon, compared to C#.
Thanks,
Lon
April 2, 2013 at 8:16 am
Bob Cullen-434885 (4/2/2013)
I selected the syntax error option but not for the reason stated. The question states SQL 2005 and higher, but THROW evidently makes its appearance with SQL 2012, so is invalid syntax is the right answer for 2005, 2008, 2008 R2, eh?So, another case of "it depends".
That is the same reason I saw the problem with the code. THROW on 2005,2008 and R2 will fail with a syntax error as well.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 15 posts - 1 through 15 (of 31 total)
You must be logged in to reply to this topic. Login to reply