SQL SERVER – A Quick Trick about SQL Server 2012 CONCAT function

Just a day before I was presenting at Virtual Tech Days and I wanted to demonstrate the current time to audience using SQL Server Management Studio, I ended up a quick error. If any of you ever tried to concat multiple values of different datatype this should not be surprise to you.

SELECT 'Current Time ' + GETDATE()

I quickly modified script to following workaround and my script worked right away.

SELECT 'Current Time ' + CAST(GETDATE() AS VARCHAR(20))

Current Time Dec 20 2011 7:00PM

However, I instantly realized that I can use SQL Server 2012 function which can right fit for this situation.

I am having Denali CTP 3. When i am trying concat function or new introduced functions, this will give me error that function not found. Can you give me
version information on which you test concat function.

Community Initiatives

About Pinal Dave

Pinal Dave is a Pluralsight Developer Evangelist. He has authored 11 SQL Server database books, 17 Pluralsight courses and have written over 3200 articles on the database technology on his blog at a http://blog.sqlauthority.com. Along with 11+ years of hands on experience he holds a Masters of Science degree and a number of certifications, including MCTS, MCDBA and MCAD (.NET). His past work experiences include Technology Evangelist at Microsoft and Sr. Consultant at SolidQ. Follow @pinaldave
Send Author Pinal Dave
an email at pinal@sqlauthority.com

Email Subscription

Enter your email address to subscribe to this blog and receive notifications of new posts by email.