How To Create User Messages with PRINT Statements in MS SQL Server?
Submitted by: AdministratorNormally, 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
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
Top MS SQL Server Questions
☺ | What Is a Transact-SQL Statement Batch in MS SQL Server? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | How To Use Subqueries with the EXISTS Operators in MS SQL Server? |
☺ | What Is a Subquery in a SELECT Query Statement in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |