Collections:
SET Statements in SQL Server Transact-SQL
How to assign value to a variable in SQL Server Transact-SQL? How to use the SET statements?
✍: FYIcenter.com
In Transact-SQL, you can use SET statements to assign values to variables
using the assignment operator =, in the syntax of:
SET @variable = <value>
When an SET statement is executed, the system will:
Here are some example on how to assign values to variables:
-- Data type matches, no implicit conversion DECLARE @price MONEY; SET @price = 9.99; PRINT @price; ---- 9.99 -- Data type does not match, implicit conversion applied DECLARE @now DATETIME; SET @now = 'Jan 1, 2000' PRINT @now; ------------------- Jan 1 2000 12:00AM -- Implicit conversion fails DECLARE @bonus MONEY; SET @bonus = 'FIFTY DOLLARS'; PRINT @bonus; ----------------------------------- Msg 235, Level 16, State 0, Line 13 Cannot convert a char value to money. The char value has incorrect syntax.
⇒ PRINT Statements in SQL Server Transact-SQL
⇐ DECLARE Statements in SQL Server Transact-SQL
2017-04-04, 2435🔥, 0💬
Popular Posts:
How To Locate and Take Substrings with CHARINDEX() and SUBSTRING() Functions in SQL Server Transact-...
Where to find SQL Server Transact-SQL language references? You can find SQL Server Transact-SQL lang...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...