In this article I will describe how to declare variables in TSQL. We can declare variables in a few different ways.
• Declare a single variable
• Declare multiple variables at once
• Set values when declaring variables
• Set values when declaring multiple variables at once
Declaring g a single variable:
1 | DECLARE @dbtut VARCHAR(50) |
We can set a value as follows to this variable.
1 | SET @dbtut='MyFirstVariable' |
Declare multiple variables at once:
1 | DECLARE @dbtut VARCHAR(50), @age INT |
Set values when declaring variables:
1 | DECLARE @dbtut VARCHAR(50)='MyFirstVariable' |
Set values when declaring multiple variables at once:
1 | DECLARE @dbtut VARCHAR(50)='MyFirstVariable',@age INT=1 |