August 21, 2012 at 7:49 am
Nice question :-). Thanks.
August 21, 2012 at 7:57 am
Nice question, learned something new today. I was quite sure the answer would be 251, but then I remembered data type precedence may be tricky.
Toreador (8/21/2012)
sestell1 (8/21/2012)
Implicit conversion isn't always your friend.Implicit conversion isn't ever your friend!
Implicit conversion isn't even your friend! π
August 21, 2012 at 8:43 am
good and easy question, thanks
--------------------------------------
;-)βEverything has beauty, but not everyone sees it.β β Confucius
August 21, 2012 at 8:48 am
Nice question about the basics. Thanks!
August 21, 2012 at 8:49 am
EL Jerry (8/21/2012)
Nice question, learned something new today. I was quite sure the answer would be 251, but then I remembered data type precedence may be tricky.Toreador (8/21/2012)
sestell1 (8/21/2012)
Implicit conversion isn't always your friend.Implicit conversion isn't ever your friend!
Implicit conversion isn't even your friend! π
I unfriended Implicit Conversion long ago.
August 21, 2012 at 8:50 am
I got it wrong on the assumption that data type conversion would take precedence over concatenation or addition. Now I understand that while I'm correct about that, the precedence does not apply to the entire statement at once, but rather on a series of left-to-right pairs. Makes sense, I suppose.
Fortunately for me I would never consider doing this implicitly. That's just asking for trouble.
ron
-----
a haiku...
NULL is not zero
NULL is not an empty string
NULL is the unknown
August 21, 2012 at 9:04 am
I am not a T-SQL person since I am primarily an Oracle DBA, but I did notice the single quotes and it make me think. The equivilent SQL in Oracle produces the same results: select '130' || '120' + 1 from dual;
HTH -- Mark D Powell --
August 21, 2012 at 9:09 am
Great tricky question!
:exclamation: "Be brave. Take risks. Nothing can substitute experience." :exclamation:
August 21, 2012 at 9:31 am
Try this one: SELECT 1+'130'+'120'+1. It comes up 252! Implicit conversion are very dangerous.
August 21, 2012 at 9:41 am
(Bob Brown) (8/21/2012)
Try this one: SELECT 1+'130'+'120'+1. It comes up 252! Implicit conversion are very dangerous.
I would expect it to.
1 + '130' = 131 ('130' converted to int)
+ '120' = 251 ('120' converted to int because the result above is an int)
+ 1 = 252 π
August 21, 2012 at 9:51 am
ronmoses (8/21/2012)
I got it wrong on the assumption that data type conversion would take precedence over concatenation or addition. Now I understand that while I'm correct about that, the precedence does not apply to the entire statement at once, but rather on a series of left-to-right pairs. Makes sense, I suppose.Fortunately for me I would never consider doing this implicitly. That's just asking for trouble.
ron
Bit me for the same reason. Agree, I wouldn't do this implicitly either.
August 21, 2012 at 10:17 am
Really interesting one - thanks!
August 21, 2012 at 11:00 am
It's very interesting how this starts as a concatenation theme, but now it has become an implicit conversion issue. By the way, the only implicit conversion in wich I trust is string to datetime. It will always works if the string provided is in 'yyyymmdd' format.
declare @s-2 nvarchar(8)
, @d1 datetime
, @d2 datetime
, @d3 datetime
set @s-2 = '20120821'
set dateformat dmy;
set @d1 = @s-2
select @d1 as date1
set dateformat mdy;
set @d2 = @s-2
select @d2 as date2
set dateformat ymd;
set @d3 = @s-2
select @d3 as date3
π
August 21, 2012 at 11:19 am
Toreador (8/21/2012)
sestell1 (8/21/2012)
Implicit conversion isn't always your friend.Implicit conversion isn't ever your friend!
+1
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
August 21, 2012 at 11:43 am
ronmoses (8/21/2012)
I got it wrong on the assumption that data type conversion would take precedence over concatenation or addition.
Made the same assumption. Since I had never implicitly converted like this, I was under the misapprehension that the datatype evaluation would go before the operations. Thanks to OP for posting, as I learned something today.
[font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
Connect to me on LinkedIn
Viewing 15 posts - 16 through 30 (of 34 total)
You must be logged in to reply to this topic. Login to reply