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 Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Use Subqueries with the IN Operators in MS SQL Server? |
☺ | How To Create a Testing Table with Test Data in MS SQL Server? |
☺ | How To Configure ODBC DSN with Different Port Numbers? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |