sp_getmessage

Description

Retrieves stored message strings from sysmessages and sysusermessages for print and raiserror statements.

Syntax

sp_getmessage message_num, result output [, language]

Parameters

message_num

is the number of the message to be retrieved.

result output

is the variable that receives the returned message text, followed by a space and the keyword output. The variable must have a datatype of char, unichar, nchar, varchar, univarchar, or nvarchar.

language

is the language of the message to be retrieved. language must be a valid language name in syslanguages table. If you include language, the message with the indicated message_num and language is retrieved. If you do not include language, then the message for the default session language, as indicated by the variable @@langid, is retrieved.

Examples

Example 1

Retrieves message number 20001 from sysusermessages:

declare @myvar varchar(200)
exec sp_getmessage 20001, @myvar output

Example 2

Retrieves the French language version of message number 20010 from sysusermessages:

declare @myvar varchar(200)
exec sp_getmessage 20010, @myvar output, french

Usage

Permissions

Any user can execute sp_getmessage. Permission checks do not differ based on the granular permissions settings.

Auditing

Values in event and extrainfo columns from the sysaudits table are:

Event

Audit option

Command or access audited

Information in extrainfo

38

exec_procedure

Execution of a procedure

  • Roles – Current active roles

  • Keywords or options – NULL

  • Previous value – NULL

  • Current value – NULL

  • Other information – All input parameters

  • Proxy information – Original login name, if set proxy in effect

See also

Commands print, raiserror

System procedures sp_addmessage, sp_dropmessage