Sunday, May 8, 2016

Create Temp Table in Sql Server or Create Temp Table Variable in Sql Server

In this post I will show how to create Temp Table(variable) using @ symbol.

Previously I had shown

OutPut:

ID
Name
IsActive
1
Kiran
1
2
Ravi
1
3
Vara
1
4
Dinesh
1
5
Deleep
0
6
Phani
1
7
Shiva
1
8
shyam
0





Syntax :
declare @TableName as table
(
       --Columns

)

Creating Table :

declare @Tbl as table
(
       ID int identity(1,1),
       Name nvarchar(max),
       IsActive bit
)

Inserting values into Temp Table

insert @Tbl (Name,IsActive)
values
('Kiran', 1),
('Ravi', 1),
('Vara', 1),
('Dinesh', 1),
('Deleep', 0),
('Phani', 1),
('Shiva', 1),
('shyam', 0)

select * from @Tbl


ID
Name
IsActive
1
Kiran
1
2
Ravi
1
3
Vara
1
4
Dinesh
1
5
Deleep
0
6
Phani
1
7
Shiva
1
8
shyam
0

No comments:

Post a Comment