IF @@OPTIONS & 512 <> 0 PRINT N'This user has SET NOCOUNT turned ON.'; ELSE PRINT N'This user has SET NOCOUNT turned OFF.'; GO ------------------------------------------------------------------ -- Build the message text by concatenating -- strings and expressions using functionality -- available in SQL Server 2000 and SQL Server 2005. PRINT N'This message was printed on ' + RTRIM(CAST(GETDATE() AS NVARCHAR(30))) + N'.'; GO -- This example shows building the message text -- in a variable and then passing it to PRINT. -- This was required in SQL Server 7.0 or earlier. DECLARE @PrintMessage NVARCHAR(50); SET @PrintMessage = N'This message was printed on ' + RTRIM(CAST(GETDATE() AS NVARCHAR(30))) + N'.'; PRINT @PrintMessage; GO ----------------------------------------------------------------- USE AdventureWorks; GO IF (SELECT SUM(i.Quantity) FROM Production.ProductInventory i JOIN Production.Product p ON i.ProductID = p.ProductID WHERE Name = 'Hex Nut 17' ) < 1100 PRINT N'There are less than 1100 units of Hex Nut 17 in stock.' GO ----------------------------------------------------------------- USE AdventureWorks; GO DECLARE @MyObject NVARCHAR(257); SET @MyObject = N'Production.Product'; PRINT N'Object Name: ' + @MyObject PRINT N' Object ID: ' + STR(OBJECT_ID(@MyObject)) GO ----------------------------------------------------------------- -- Build a print message by concatenating strings in a PRINT -- statement. PRINT N'The Database Engine instance ' + RTRIM(@@SERVERNAME) + N' is running SQL Server build ' + RTRIM(CAST(SERVERPROPERTY(N'ProductVersion ') AS NVARCHAR(128))); GO -- This shows building a character variable that is used to -- print a message. DECLARE @Msg NVARCHAR(300); SELECT @Msg = N'The Database Engine instance ' + RTRIM(@@SERVERNAME) + N' is running SQL Server build ' + RTRIM(CAST(SERVERPROPERTY(N'ProductVersion') AS NVARCHAR(128))); PRINT @Msg; GO ----------------------------------------------------------------- ----------------------------------------------------------------- -----------------------------------------------------------------