SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


concatenation


concatenation

Author
Message
Thomas Abraham
Thomas Abraham
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3861 Visits: 2256
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.
Connect to me on LinkedIn
Raghavendra Mudugal
Raghavendra Mudugal
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3386 Visits: 2958
Thanks for the good question. Smile

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
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63904 Visits: 13298
Great question, thanks!


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

MCSE Business Intelligence - Microsoft Data Platform MVP
Andrew Watson-478275
Andrew Watson-478275
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2215 Visits: 2754
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)
Rose Bud
Rose Bud
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1793 Visits: 1062
I particularly liked this question because I got it wrong but shouldn't have!
Tom Thomson
Tom Thomson
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26269 Visits: 12506
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search