|Programming in MS SQL Server 2012|
Transact-SQL local variable is an object that helps to store a single data value of a specific data type. Transact-SQL variables are typically used for
01. To count the number of times a loop is performed or to control how may times the loop is performed in conditional statement.
02. To hold a data value to be tested by a control-of-flow statement.
03. To save a data value to be returned by a stored procedure return code or function return value.
DECLARE statement initializes a Transact-SQL variable by assigning a variable name. The local variable must start with @ symbol and end with data type and data size. Decimal and Float variable must define with precision and scale. The following statements are used to define different types of variables in SQL Server.
To declare more than one local variable, use a comma after the first local variable defined, and then specify the next local variable name and data type.
SELECT or SET statement is used to stores variable initial data value followed by = equal operator.
* * * * *