|
Home >> FAQs/Tutorials >> SQL Server FAQ
SQL Server FAQ - PRINT - Returning User Messages
By: FYIcenter.com
(Continued from previous topic...)
How To Create User Messages with PRINT Statements?
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 localhost\sqlexpress -U sa -P FYIcenter
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.
(Continued on next topic...)
- What Is SQL Language?
- What Is Transact-SQL Language?
- What Is a Transact-SQL Statement?
- How To Start and End Transact-SQL Statements?
- How To Enter Comments in Transact-SQL Statements?
- What Is a Transact-SQL Statement Batch?
- What Happens to a Statement Batch If There Is a Compilation Error?
- How To Use GO Command in "sqlcmd"?
- How To Create User Messages with PRINT Statements?
- How Many Categories of Data Types Used by SQL Server?
- What Are Exact Numeric Data Types?
- What Are Approximate Numeric Data Types?
- What Are Date and Time Data Types?
- What Are Character String Data Types?
- What Are Unicode Character String Data Types?
- What Are Binary String Data Types?
- What Are the Differences between CHAR and NCHAR?
- What Are the Differences between CHAR and VARCHAR?
- What Are the Differences between DECIMAL and FLOAT?
|