print

Prints a user-defined message on the user’s screen.

Syntax

print 
	{format_string | @local_variable | 
	@@global_variable}
		[, arg_list]

Parameters

Examples

Usage

  • The maximum output string length of format_string plus all arguments after substitution is 1023 bytes.

  • If you use placeholders in a format string, keep this in mind: for each placeholder n in the string, the placeholders 1 through n- 1 must also exist in the same string, although they do not have to be in numerical order. For example, you cannot have placeholders 1 and 3 in a format string without having placeholder 2 in the same string. If you omit a number in a format string, an error message is generated when print is executed.

  • The arg_list must include an argument for each placeholder in the format_string, or the transaction is aborted. You can use more arguments than placeholders.

  • To include a literal percent sign as part of the error message, use two percent signs (‘‘%%’’) in the format_string. If you include a single percent sign (‘‘%’’) in the format_string that is not used as a placeholder, the SAP ASE server returns an error message.

  • If an argument evaluates to NULL, it is converted into a zero-length character string. If you do not want zero-length strings in the output, use the isnull function. For example, if @arg is null, the following statement prints I think we have nothing here.:
    declare @arg varchar (30) 
    select @arg = isnull (col1, "nothing") from 
    table_a where ...
    print "I think we have %1! here", @arg
  • You can add user-defined messages to the system table sysusermessages for use by any application. Use sp_addmessage to add messages to sysusermessages; use sp_getmessage to retrieve messages for use by print and raiserror.

  • Use raiserror instead of print to print a user-defined error message and have the error number stored in @@error.

See also sp_addmessage, sp_getmessage in Reference Manual: Procedures.

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

No permission is required to use print.

Related reference
declare
raiserror