SQL SERVER – A Quick Trick about SQL Server 2012 CONCAT Function – PRINT

Yesterday I posted A Quick Trick about SQL Server 2012 CONCAT function and the very first comment in few minutes of Vinod Kumar. He suggested that this function should be also used with the PRINT statement as well. While I was having conversation with him – Jacob Sebastian sent me message suggesting the same. As I got feedback in first 10 minutes of publishing the blog post – I decided to update the blog post. While I started to write there was an email from Rick Morelan suggesting that this function can be used along with PRINT statement. Alright – 3 SQL experts suggesting the same thing to me in less than 15 minutes. Here is the dedicated post addressing the same idea.

Here is the question how many of you had the same suggestion as Vinod, Jacob and Rick?

Here is the updated version of the same article. If you use PRINT statement and directly appending string and datetime datatype you will get following error.

PRINT 'Current Time ' + GETDATE()

SQL SERVER - A Quick Trick about SQL Server 2012 CONCAT Function - PRINT concaterror

The normal reaction to the same is to modify the script and convert datetime datatype to varchar datatype. This will not only remove the error but also a very common practice.

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

Current Time Dec 21 2011  7:00PM

Just like earlier blog post you can now use SQL Server 2012 function CONCAT to resolve the error.

PRINT CONCAT('Current Time ', GETDATE())

I have previously written in detail article about SQL Server 2012 CONCAT function over here additionally, I have written quick guide on 14 new functions of SQL Server Denali.

I am sure Vinod, Jacob and Rick are smiling at looking at this blog post.

Watch a quick video relevent to this subject:
[youtube=http://www.youtube.com/watch?v=HbbRpg-tHz4]

Reference: Pinal Dave (https://blog.sqlauthority.com)

SQL Function, SQLAuthority Book Review
Previous Post
SQLAuthority News – Introduction to expressor Connectivity to Salesforce – expressor Data Integration Applications
Next Post
SQL SERVER – Mastering the Basics – Igniting Learning – A Unique Learning Experience

Related Posts

Leave a Reply