Books Online: Bad example for FORMATMESSAGE - by Kostja

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 775684 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 1/3/2013 4:09:02 AM
Access Restriction Public


The current documentation for FORMATMESSAGE at contains the following example:

SELECT @var1 = FORMATMESSAGE(50001, 'Table1', 5)

I believe this to be a bad example, because it is nothing a user could just run and try out. This is because the message 50001 does not exist by default in sys.messages and no result is returned. Even if you would return the value of @var1 it would be null without adding a message to the catalog.

I think this could be improved in different ways:
1. If you want to continue using message 50001, add code to add it to the catalog to the example.
2. Add code to return the content of @var1.
3. Add semicolons to the code.

You could also use an existing message if you don't like to include the sp_addmessage part like so:

SELECT @var1 = FORMATMESSAGE(21874, 'SP1', 'DB1');
SELECT @var1;
Sign in to post a comment.
Posted by Rick [MSFT] on 1/3/2013 at 1:23 PM
I wanted to avoid the mispelled word which must be fixed by other people. So I replaced the example with:

SELECT text FROM sys.messages WHERE message_id = 20009 AND language_id = 1033;
SELECT @var1 = FORMATMESSAGE(20009, 'First Variable', 'Second Variable');
SELECT @var1;
And changed the description of the example as well. It will take several weeks to appear online. Thank you for helping us fix this.
Posted by Rick [MSFT] on 1/3/2013 at 8:26 AM
Thanks. I saw your SQLServer-MVP-NDA post this morning. I'll take a look. Rick Byham