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 123»»»

SQL Server 2012 Concat Expand / Collapse
Author
Message
Posted Monday, July 8, 2013 9:40 PM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: 2 days ago @ 7:49 AM
Points: 608, Visits: 1,027
Comments posted to this topic are about the item SQL Server 2012 Concat

Pramod
SQL Server DBA | MCSA SQL Server 2012

in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
Post #1471427
Posted Monday, July 8, 2013 10:21 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, June 24, 2014 6:38 PM
Points: 1,371, Visits: 1,560
Nice and easy! Thanks Pramod

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1471432
Posted Monday, July 8, 2013 11:35 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:34 AM
Points: 1,888, Visits: 2,326
Lokesh Vij (7/8/2013)
Nice and easy! Thanks Pramod

+1



_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1471441
Posted Monday, July 8, 2013 11:38 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
Quite easy, Really very good question. Still 36% people are wrong. It shows important of this question.
Keep it up man !!!




Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1471442
Posted Tuesday, July 9, 2013 1:25 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:33 AM
Points: 2,469, Visits: 2,346
select concat(null + 'Hello','testString') as a
, null+'testString' as b

It simply returns 'testString', NULL
Post #1471457
Posted Tuesday, July 9, 2013 1:30 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: 2 days ago @ 7:49 AM
Points: 608, Visits: 1,027
Carlo Romagnano (7/9/2013)
select concat(null + 'Hello','testString') as a
, null+'testString' as b

It simply returns 'testString', NULL


Looks ok to me as :
null + 'Hello' --->NULL


Pramod
SQL Server DBA | MCSA SQL Server 2012

in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
Post #1471458
Posted Tuesday, July 9, 2013 1:55 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:33 AM
Points: 2,469, Visits: 2,346
Some formatting with CONCAT:
SELECT 
concat
(
'Name: ',t.name
,CHAR(9) + 'Last name: ',t.lastname
,CHAR(9) + 'Total: ',SUM(e.Score)
) AS csv_line
FROM Students t
JOIN Exams e
ON t.ID = e.ID_Student
GROUP BY t.name
,t.lastname

Post #1471465
Posted Tuesday, July 9, 2013 3:13 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:59 AM
Points: 5,930, Visits: 8,181
Carlo Romagnano (7/9/2013)
select concat(null + 'Hello','testString') as a
, null+'testString' as b

It simply returns 'testString', NULL

Yup. If you wanted to get 'HellotestString', you'd use SELECT CONCAT(NULL, 'Hello', 'testString');



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1471490
Posted Tuesday, July 9, 2013 3:16 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:33 AM
Points: 2,469, Visits: 2,346
Hugo Kornelis (7/9/2013)
Carlo Romagnano (7/9/2013)
select concat(null + 'Hello','testString') as a
, null+'testString' as b

It simply returns 'testString', NULL

Yup. If you wanted to get 'HellotestString', you'd use SELECT CONCAT(NULL, 'Hello', 'testString');

No, I didn't want!
It's a joke!
Post #1471492
Posted Tuesday, July 9, 2013 3:40 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 5:31 PM
Points: 8,577, Visits: 9,090
Nice straightforward question. Good to see a question about another new feature in SQL 2012.

However, introducing a weird ODBC function into T-SQL seems to me a bad idea. It's treatment of NULL is a mechanism to allow people to continue to misuse null once the ability to switch ANSI nulls off is removed, and continue to write obscure buggy code instead of cleaning things up.

I guess the ability to write (for example) "concat(5,6,7,8)" and get 5678 might be considered useful, because it saves a bit of typing - not in the case of literals since "'5'+'6'+'7'+'8'" is 15 characters and so is the expression with concat - but when the arguments are column names "concat(c1,c2,c3,c4)" is quite a lot shorter than "cast(c1 as varchar)+cast(c2 as varchar)+cast(c3 as varchar)+cast(c4 as varchar)" but I don't believe the benefits of being able to do that (of similar things with float) outweigh the scope for misuse of this form of null handling, so on balance I feel concat is something I would rather live without.


Tom
Post #1471505
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse