July 9, 2014 at 11:57 pm
Comments posted to this topic are about the item What is the Output?
Thanks,
Shiva N
Database Consultant
July 9, 2014 at 11:58 pm
Nice one, thanks for sharing
Thanks
July 10, 2014 at 1:04 am
Nice question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
July 10, 2014 at 3:38 am
This was removed by the editor as SPAM
July 10, 2014 at 5:26 am
thanks for this
July 10, 2014 at 5:34 am
Thank you for the post, very good one.
ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
July 10, 2014 at 5:43 am
Nice Q, thanks. My logic on data type promotion was right, but my arithmetic was lacking 🙂
July 10, 2014 at 5:47 am
And here I didn't count the declare as line 1. DOH!
July 10, 2014 at 6:48 am
Thanks for question Shiva.
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
July 10, 2014 at 7:34 am
Good question, Shiva. Thanks!
July 10, 2014 at 8:48 am
Good question, and teh correct answer is right (unlike quite a few QotDs). But I have a niggle about the explanation.
Clearly the conversion of @intB to bigint in line 4 is not done explicitly as implied by the explanation: there is no cast or conversion operator that applies to @intB. In fact in line 4, @intB is automatically converted to bigint (implicit conversion caused because bigint comes before int in type precedence order) so there certainly is an automatic promotion from int to bigint.
What's happening in line 7 is that the first calculation is @intB+1 because in the absence of brackets expressions are evaluated from left to right except when this is overridden by operator precedence and here there are no brackets and both operators are + so they have the same precedence, and there is no bigint element in that subexpression to cause implicit conversion from int, so the calculation is attempted as an int calculation which fails because the result would not be a valid int.
Not really a technical error, just bad/misleading phrasing.
Tom
July 11, 2014 at 4:07 am
Nice question, Thanks for sharing
July 14, 2014 at 1:37 am
Good back to basics, thanx a lot 🙂
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
August 20, 2014 at 7:40 am
Nice Q? However I did not get it right.
January 14, 2015 at 11:31 pm
Nice question.. Good to know that following is not failing.. Order does matter
DECLARE @intA INT = 2147483647, @intB INT = -2147483648, @intC INT --1
SELECT @intC = @intB + 1 + @intA --6
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply