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: Tuesday, November 18, 2014 12:29 PM
Points: 1,945, Visits: 3,121
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 @ 11:20 AM
Points: 1,392, Visits: 2,401
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: Yesterday @ 4:43 PM
Points: 1,357, Visits: 1,726
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


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: Thursday, November 13, 2014 3:37 PM
Points: 695, Visits: 310
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 @ 9:26 AM
Points: 1,802, Visits: 6,571
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 @ 9:15 AM
Points: 1,329, Visits: 2,615
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: Wednesday, November 19, 2014 1:50 PM
Points: 3,798, Visits: 1,221
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

To better understand your help request, please follow these best practices.
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: Yesterday @ 11:01 AM
Points: 1,113, Visits: 1,089
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: Wednesday, November 19, 2014 12:24 PM
Points: 3,384, Visits: 2,017
Nice question about the basics. Thanks!
Post #1347832
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse