August 11, 2014 at 7:59 am
Good question, thanks, Hugo.
August 11, 2014 at 11:21 am
Thank you for the post, Hugo, good one.
(so simple... declaration takes precedence of value assignment, even though it is in-line)
ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
August 11, 2014 at 12:42 pm
Thanks, all, for the nice words!
Sektor / Iulian: Yes, this is indeed different from C#, which (as far as I know - probably not very far) uses multiple-pass compilation. T-SQL uses single-pass, and has very different scoping rules. As far as I know, that is indeed by design, though badly documented.
thokozanik (8/11/2014)
Hugo, I thought the reason why the answer is null is because the evaluation of IF 1 < 0 get returned as false
That is part of the explanation. Because 1 < 0 evaluates as false, the (implied) SET statement that gives @j-2 its value is never executed. (And neither is the SET that changes the value of @i, though that becomes irrelevant for the question once you realize why @j-2 is not initialized at all).
August 11, 2014 at 3:20 pm
Nice little question, and great explanation. Thanks.
August 12, 2014 at 10:33 pm
Nice one, thanks Hugo
Thanks
August 13, 2014 at 6:35 am
Tricky.. lost my points
Viewing 7 posts - 16 through 22 (of 22 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy