Home Dashboard Directory Help
Search

Books Online: Bad example for FORMATMESSAGE by Kostja


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 775684
Opened: 1/3/2013 4:09:02 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

The current documentation for FORMATMESSAGE at http://msdn.microsoft.com/en-us/library/ms186788.aspx contains the following example:

DECLARE @var1 VARCHAR(100)
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:

DECLARE @var1 VARCHAR(200);
SELECT @var1 = FORMATMESSAGE(21874, 'SP1', 'DB1');
SELECT @var1;
Details
Sign in to post a comment.
Posted by Microsoft 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;
DECLARE @var1 VARCHAR(200);
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 Microsoft 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
Sign in to post a workaround.