Thursday, 27 July 2017

FORMATMESSAGE function in SQL Server 2016

FORMATMESSAGE Function in SQL Server 2016 

In the previous versions of Sql server, this function was used to construct a message from strings located in sys.messages.

FORMATMESSAGE statement is enhanced in SQL Server 2016 to enable supply your own string values.

Syntax: FORMATMESSAGE ( { msg_number  | ' msg_string ' } , [ param_value [ ,...n ] ] ) 

Example:-

DECLARE @ExampleMessage VARCHAR(150)

SET @ExampleMessage = FORMATMESSAGE('code-sample very popular from %s year and this is included in top %s best site','2013','5');

SELECT @ExampleMessage AS 'OUTPUT';     

OUTPUT
code-sample very popular from 2013 year and this is included in top 5 best site


SELECT FORMATMESSAGE('%s and  %s is the most popular tutorial sites for the develper', 'www.code-sample.com', 'www.code-view.com') AS Result;

Result

www.code-sample.com and  www.code-view.com is the most popular tutorial sites for the developer

No comments:

Post a Comment