Reputation: 1
What is the difference between one @ and two @@ in the SQL programming language? Also, how do you get a table into the temporary tables in an SSMS database?
Upvotes: 0
Views: 553
Reputation: 2613
Difference between @ and @@:
@ is a Local variable to hold some value depending on its type and range. @@ Global variable and it refers to a function name. We have some system functions defined in SQL server
How do you get a table into the temporary tables in an SSMS database?
I assume you want to Insert data from normal tables to Temp tables
Here are the steps:
First create a temporary table, SQL in below:
---CREATE TEMP TABLE
Create Table #MyTempTable (
EmployeeID int
);
INSERT data into temporary table with SELECT statement from original table
----INSERT COMMON DATA
Insert Into #MyTempTable
Select EmployeeID from Employee Where EmployeeID between 1 and 10
Sometimes there's no need to predefine a temp table. It will be created from results of the select.
Select FieldA...FieldN
into #MyTempTable
from MyTable
Upvotes: 0
Reputation: 14928
The @@
is a Configuration Functions or even a Global Variable.
The @
is a variable.
Also, how do you get a table into the temporary tables in an SSMS database?
Thers is no SSMS database, SSMS (SQL Server Management Studio) is a graphical tool.
SSMS is an integrated environment for managing any SQL infrastructure, from SQL Server to Azure SQL Database. SSMS provides tools to configure, monitor, and administer instances of SQL. Use SSMS to deploy, monitor, and upgrade the data-tier components used by your applications, as well as build queries and scripts.
To create a temp table from an existing table
SELECT * FROM YourTable INTO #TempTable;
Upvotes: 1
Reputation: 6524
In earlier versions of SQL Server, @
was a variable name and @@
was a global variable. After 2008 R2, @
is a valid character identifier. So, @tempVar
, @@tempVar
@@@tempVar
... are all valid variables.
However, if you have a system function which shares the same name as @@ variable, then it will not compile. Example:
Upvotes: 0
Reputation: 1269953
A handy way to think about it is that a single @
is a local variable and a @@
is a global variable. Local variables are either declared explicitly using DECLARE
or as a parameter to a stored procedure or function.
The @@
"variables" are defined globally.
This is not 100% accurate. As explained in the documentation:
The names of some Transact-SQL system functions begin with two at signs (@@). Although in earlier versions of SQL Server, the @@functions are referred to as global variables, they are not variables and do not have the same behaviors as variables. The @@functions are system functions, and their syntax usage follows the rules for functions.
Upvotes: 3