Tags

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


NEW T-SQL FEATURES IN SQL SERVER 2016- X [ FORMATMESSAGE() ) ]

In this post we shall check out the new features Microsoft introduced in SQL Server 2016.

New feature – X [ FORMATMESSAGE() ) ]

With this function we can format our string just like what we have do with the printf(https://en.wikipedia.org/wiki/Printf_format_string) statement in C language.

Notes:-

1. You will recive an error if the formatting has issue(s). The error will be “Error: 50000, Severity: -1, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.”

Example of FORMATMESSAGE with SELECT

--

SELECT FORMATMESSAGE('Hi, This is %s with %s.', 'Pawan', 'SQL SERVER') Outs

--

OUTPUT

--

Outs
----------------------------------------------
Hi, This is Pawan with SQL SERVER.

(1 row affected)

--

Example of FORMATMESSAGE with PRINT

--

PRINT FORMATMESSAGE('Hi, This is %s with %s.', 'Pawan', 'SQL SERVER')  


--

OUTPUT

--

Hi, This is Pawan with SQL SERVER.

--

Another Example of FORMATMESSAGE with PRINT

--

PRINT FORMATMESSAGE('Color %s, float %d', 'red', 20)


--

OUTPUT

--

Color red, float 20

--

Refer Microsoft LINK below for more details-

1.https://msdn.microsoft.com/en-us/library/ms186788(v=sql.110).aspx

Enjoy !!! Keep Learning

Pawan Khowal 

Http://MSBISkills.com

Advertisements