Home > DeveloperSection > Forums > How to create global temporary table in Sqlserver.
Ankit Singh

Total Post:341

Posted on    October-30-2015 2:18 AM

 .NET SQL Server  SQL 

 1 Reply(s)
 495  View(s)
Rate this:
Can anyone please help me how to solve this problem.

aditya kumar Patel

Total Post:254

Posted on    October-30-2015 2:29 AM

SQL Server provides the concept of temporary table which helps the developer in a best way. These tables can be created at runtime and can do the all kinds of operations that one normal table can do. But, based on the table types, the scope is limited. These tables are created inside tempdb database. Global Temporary tables name starts with a double hash ("##"). Once this table has been created by a connection, like a permanent table it is then available to any user by any connection. It can only be deleted once all connections have been closed.

 --step 1 create global temporary table

CREATE TABLE ##globaltemptbl



OrderID int, rderdate datetime,

amount decimal(10,2)



--step-2 insert data in #globaltemptabl from order table

insert into ##globaltemptbl select * from [Order]

--step-3 select data from #globaltemptabl

select * from ##globaltemptbl

Modified On Oct-30-2015 03:04:21 AM

Don't want to miss updates? Please click the below button!

Follow MindStick