I have encountered some T-SQL codes where the original author used @Date to express dates. What does the @ mean and what is its functionality?
Declare @VariableName Int
SET @BeginDate = database.BeginDate(@BeginDate)
I have encountered some T-SQL codes where the original author used @Date to express dates. What does the @ mean and what is its functionality?
Declare @VariableName Int
SET @BeginDate = database.BeginDate(@BeginDate)
The at (@
) symbol in SQL Server is a mandatory prefix in a variable name,
Not to be confused with system-defined built in functions which are prefixed with a double at symbol (@@
) such as @@rowcount, @@version, @@spid etc'.
A local variable is declared using the declare
keyword.
The declare expression has three mandatory parts:
The declare
keyword, the variable name, and the variable data type (Which can be either system-provided or user-defined type, scalar or table).
The declare
expression also has an optional part which enables you to set an initial value to your variable, which is only applicable for scalar variables.
The following code line declares an int variable called @VariableName, with the initial value of null
(all SQL Server scalar data types are nullable by default except for sysname
).
Declare @VariableName Int;
To set it's initial value to, say, 5, you can write this statement like this:
Declare @VariableName Int = 5;
local variables can also be populated using the set
statement or the select
statement.
Assigning a name. The name must have a single @ as the first character.
Please check