October 12, 2012 at 5:42 am
demonfox (10/12/2012)
Lokesh Vij (10/11/2012)
Thanks Sreenivas for the question. Indeed we discussed the situation of "Divide by zero error" in your earlier QOTD discussion forum "While Loop - 1".All in all ending this week on a good note 🙂
And I didn't have to rethink for this one..;-):w00t::hehe:
I hope demonfox, you were the one who started that "Divide by Zero" post the other day 🙂
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
October 12, 2012 at 6:41 am
Thanks for the question. I almost answered it wrong 'til I had a second look at it. Thank goodness for morning caffeine. 😀
October 12, 2012 at 7:14 am
it's my mistake. i read few lines and gave the answer without reading it completely.
Anyway good question.:-)
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
October 12, 2012 at 8:17 am
I guess the thing that confuses me is, if the variable @ctr is declared within the try block, and the try block fails, why the variable would even exist to be selected in the catch block. Clearly it is, I just don't understand the logic.
Then again, I'd never declare a variable within a try block anyway, so...
ron
-----
a haiku...
NULL is not zero
NULL is not an empty string
NULL is the unknown
October 12, 2012 at 8:54 am
Great question!
October 12, 2012 at 9:16 am
ronmoses (10/12/2012)
I guess the thing that confuses me is, if the variable @ctr is declared within the try block, and the try block fails, why the variable would even exist to be selected in the catch block. Clearly it is, I just don't understand the logic.Then again, I'd never declare a variable within a try block anyway, so...
ron
Variables in SQL are not block scoped - you can put variable declarations between begin and end and use the variables after the end.
I have a vague recollection from ancient times that someone wanted to be purist about begin and end being compound statement brackets for control flow, nothing to do with lexical scope. SQL variables are module (stored procedure, trigger, udf) scoped and batch scoped. As far as I recall, SQL is the only mainstream language that ever did this (but I've forgotten more computer languages than I remember, so I could easily be wrong).
The scope of a variable lasts from the point it is declared until the end of the batch or stored procedure in which it is declared.
Tom
October 12, 2012 at 9:32 am
Variables in SQL are not block scoped - you can put variable declarations between begin and end and use the variables after the end.
I have a vague recollection from ancient times that someone wanted to be purist about begin and end being compound statement brackets for control flow, nothing to do with lexical scope. SQL variables are module (stored procedure, trigger, udf) scoped and batch scoped. As far as I recall, SQL is the only mainstream language that ever did this (but I've forgotten more computer languages than I remember, so I could easily be wrong).
Perl will let you do this if you don't use strict. Otherwise T-SQL is unique in this way, and a bit odd.
Tony
------------------------------------
Are you suggesting coconuts migrate?
October 12, 2012 at 9:33 am
I wonder how the 17% can think that a variable of type int can hold a "Error" value. May be null, but error?
By the way, what is the "Error" value? 😛
October 12, 2012 at 9:47 am
Saw the division by zero error.... and knew it was 4.
Thanks for a question that I can unequivically feel that I know the answer to 🙂
October 12, 2012 at 11:36 am
Nice question. Thanks!
October 14, 2012 at 10:13 am
Thanks for the question
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
October 16, 2012 at 10:14 am
Good Question +1
October 24, 2012 at 8:18 pm
Good question. Thanks for submitting.
http://brittcluff.blogspot.com/
January 9, 2013 at 2:22 am
As easy and basic as the previous QOTD
Viewing 15 posts - 16 through 29 (of 29 total)
You must be logged in to reply to this topic. Login to reply