Export (0) Print
Expand All
ABS
ALL
AND
ANY
AVG
bit
COS
COT
DAY
EXP
GO
IN
LEN
LOG
MAX
MIN
NOT
OR
PI
SET
SIN
STR
SUM
TAN
USE
VAR
Expand Minimize
2 out of 5 rated this helpful - Rate this topic

PRINT

SQL Server 2000

Returns a user-defined message to the client.

Syntax

PRINT 'any ASCII text' | @local_variable | @@FUNCTION | string_expr

Arguments

'any ASCII text'

Is a string of text.

@local_variable

Is a variable of any valid character data type. @local_variable must be char or varchar, or be able to be implicitly converted to those data types.

@@FUNCTION

Is a function that returns string results. @@FUNCTION must be char or varchar, or be able to be implicitly converted to those data types.

string_expr

Is an expression that returns a string. Can include concatenated literal values and variables. The message string can be up to 8,000 characters long; any characters after 8,000 are truncated.

Remarks

To print a user-defined error message having an error number that can be returned by @@ERROR, use RAISERROR instead of PRINT.

Examples
A. Conditionally executed print (IF EXISTS)

This example uses the PRINT statement to conditionally return a message.

IF EXISTS (SELECT zip FROM authors WHERE zip = '94705')
   PRINT 'Berkeley author'
B. Build and display a string

This example converts the results of the GETDATE function to a varchar data type and concatenates it with literal text to be returned by PRINT.

PRINT 'This message was printed on ' + 
   RTRIM(CONVERT(varchar(30), GETDATE())) + '.'

See Also

Data Types

DECLARE @local_variable

Functions

RAISERROR

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.