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 6:09 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Sunday, June 16, 2013 3:45 AM
Points: 688, Visits: 163
Thanks for the question. I ran in to a similar situation while creating a query last week.
Post #1347739
Posted Tuesday, August 21, 2012 6:20 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 7:51 AM
Points: 1,945, Visits: 2,864
this is why we use || in ANSI Standard SQL for concatenation.

Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1347742
Posted Tuesday, August 21, 2012 6:31 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 10:33 AM
Points: 1,282, Visits: 2,219
Nice question, and a nice example showing that data type issues don't always result in an error. Implicit conversion isn't always your friend.

Post #1347744
Posted Tuesday, August 21, 2012 7:02 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 11:40 AM
Points: 1,297, Visits: 1,660
Prassad Dabbada V R (8/21/2012)
I thought it will conevert everything to int. As the expression eveluates from right to left so from the right first plus will return 121 (120 will be converted to int) and so on and so forth.
but unfortunately my guess is wrong.


No, expressions evaluate from left to right.

I got it wrong because I'm so used to shortcutting the addition of 3 numbers in my head that I for some reason thought SQL Server could do the same. Too early in the morning, not enough coffee, {{insert additional generic excuse}}.
Post #1347761
Posted Tuesday, August 21, 2012 7:28 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 1:15 PM
Points: 634, Visits: 282
Good question..! I m woundering why almost 50% attempts are wrong.

Best,
Naseer Ahmad
SQL Server DBA
Post #1347785
Posted Tuesday, August 21, 2012 7:30 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 8:40 AM
Points: 1,715, Visits: 6,265
sestell1 (8/21/2012)
Implicit conversion isn't always your friend.


Implicit conversion isn't ever your friend!
Post #1347786
Posted Tuesday, August 21, 2012 7:49 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 8:39 AM
Points: 1,312, Visits: 2,496
Nice question . Thanks.


Sujeet Singh
Post #1347798
Posted Tuesday, August 21, 2012 7:57 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 3:28 PM
Points: 3,790, Visits: 1,108
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!


"El" Jerry.

"A watt of Ottawa" - Gerardo Galvan
Post #1347804
Posted Tuesday, August 21, 2012 8:43 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, July 28, 2014 11:47 AM
Points: 1,019, Visits: 1,003
good and easy question, thanks

--------------------------------------
"Stay Hungry, Stay Foolish." ― Jobs
“Everything has beauty, but not everyone sees it.” ― Confucius

Post #1347826
Posted Tuesday, August 21, 2012 8:48 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 10:45 AM
Points: 3,266, Visits: 1,959
Nice question about the basics. Thanks!
Post #1347832
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse