How to make temp table in SQL server

                How to make temp table in SQL  server

A temporary table in SQL Database,  is a database table that exists temporarily on the database . A temporary table stores a subset of data from a normal table for a certain period of time.


Lets See how to create temp table and hold data in it.





        DROP TABLE IF EXISTS  #tempdat
        GO
        CREATE TABLE #tempdata
          (
         CustomerID int,
         CustomerName nvarchar(64),
          Address nvarchar (max),
          Creationdate dateime
           )


            ;with CTE as 
             (  
   select CustomerID ,CustomerName ,Creationdate ,Address  from customertable where       Customer ID =anyID
)


 insert into #tempdata  select from CTE;

 select * from  #tempdata
 GROUP BY CustomerID,CustomerName,Address
 ORDER BY CustomerID



It is very easy to store data temporarily and use it accordingly from that table

No comments:

Post a Comment