Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234

concatenation Expand / Collapse
Author
Message
Posted Tuesday, August 21, 2012 11:43 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 4:58 AM
Points: 1,152, Visits: 1,457
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.


Please don't go. The drones need you. They look up to you.
Post #1347992
Posted Wednesday, August 22, 2012 12:03 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 4:14 AM
Points: 447, Visits: 1,199
Thanks for the good question. :)

wish to see more like this.

(I guess this depends on the initial type of the data which in the first position.

For this "select '130'+'120'+1" it will give you 130121, but for this "select 1+'120'+'130'" it will give you 251 not 121130. It takes the next value and it converts to the first value's data-type and then so on...

select 0 + '130'+'120'+1 - this gives 251 (because the initial value type is number and it works for only int type)

select 0 + '130'+'120'+2.56 - and the decimal works only with the end value.)


ww; Raghu
--
There are only 10 types of people in the world, those who understand binary, and those who don't.

Note: (as of now) only.. 1 and 4 applies (i am on my way...)
Post #1348195
Posted Wednesday, August 22, 2012 12:17 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 2:11 AM
Points: 9,378, Visits: 6,473
Great question, thanks!



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1348198
Posted Wednesday, August 22, 2012 2:53 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Saturday, May 18, 2013 1:44 AM
Points: 953, Visits: 1,875
I guess this depends on the initial type of the data which in the first position.

Not entirely true. (Try '130' + 1 + '120' => 251)

If you see the links I posted earlier, the key in this case is datatype precedence. It takes the operands and applies the precedence rules - in this case, the integer takes priority, regardless of whether it's first or second.

http://msdn.microsoft.com/en-us/library/ms190276 (operator precedence)
http://msdn.microsoft.com/en-us/library/ms190309 (data type precedence)
Post #1348257
Posted Thursday, August 23, 2012 8:35 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:42 AM
Points: 1,072, Visits: 1,026
I particularly liked this question because I got it wrong but shouldn't have!
Post #1349152
Posted Sunday, September 02, 2012 9:00 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 12:25 PM
Points: 7,110, Visits: 7,184
Hugo Kornelis (8/21/2012)
A good question. I'll admit that I am surprised at the high number of incorrect answers; I would have expected 70 to 80 percent to get this right.
I'm not surprised that the wrong answers are fairly evenly divided over the wrond answers; they are all very good distractors. Well done!

And Andrew, thank you for providing the links and explanation that really explain the results; they are a good addition to the explanation and references given bij Yousaf.

+1 - although I've noticed before that people get confused about evaluation order where operators have the same precedence, which probably accounts for some of the "251" answers.


Tom
Is minic a gheibheann béal oscailte dorn dúnta.
Is minig a cheapas beul fosgailte dòrn dùinte.
Post #1353226
« Prev Topic | Next Topic »

Add to briefcase «««1234

Permissions Expand / Collapse