-2

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)
ACuriousCat
  • 1,003
  • 1
  • 8
  • 21
  • https://www.techonthenet.com/sql_server/declare_vars.php Does this answer your question – Amanjot Kaur Nov 12 '19 at 08:20
  • https://learn.microsoft.com/en-us/sql/t-sql/language-elements/variables-transact-sql?view=sql-server-2017#declaring-a-transact-sql-variable – Zohar Peled Nov 12 '19 at 10:34
  • 1
    I'm voting to close as off-topic because this is basically asking SO to write any basic tutorial on T-SQL, which you should read before asking questions. – underscore_d Nov 12 '19 at 12:16
  • 2
    I'm voting to close this question as off-topic because this question is easily googled and does not require a SO topic, there is no special need for this question here. – SAS Nov 12 '19 at 13:08
  • Does this answer your question? [What does the "@" symbol do in SQL?](https://stackoverflow.com/questions/361747/what-does-the-symbol-do-in-sql) – Jayakumar Thangavel Nov 19 '19 at 10:30

2 Answers2

1

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.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
0

Assigning a name. The name must have a single @ as the first character.

Please check

https://learn.microsoft.com/en-us/sql/t-sql/language-elements/variables-transact-sql?view=sql-server-ver15

Jayakumar Thangavel
  • 1,884
  • 1
  • 22
  • 29