How To Create User Messages with PRINT Statements in MS SQL Server?

Submitted by: Administrator
Normally, messages are generated by SQL Server and returned to the client applications associated with the execution result of statement batches. But you can define your messages and ask the SQL Server to your client session with the PRINT statement, as shown in this tutorial exercise:

C:>sqlcmd -S localhostsqlexpress -U sa -P GlobalGuideLine
1> PRINT 'What time is it?';
2> SELECT GETDATE();
3> GO
What time is it?

-----------------------
2007-05-19 21:51:23.797

(1 rows affected)

1> PRINT 'What time is it?';
2> PRINT 'It''s '+CAST(GETDATE() AS NVARCHAR(30));
3> GO
What time is it?
It's May 19 2007 9:55PM

Note that the SELECT statement returns query result, which is very different than messages returned by the PRINT statement.
Submitted by: Administrator

Read Online MS SQL Server Job Interview Questions And Answers