How to create local temporary table in Sqlserver.

Total Post:341

 966  View(s)
Rate this:
Can anyone please help me how to solve this problem.
  1. Post:282

    Re: How to create temporary table in Sqlserver.

    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. Local temp tables are only available to the current connection for the user; and they are automatically deleted when the user disconnects from instances. Local temporary table name is stared with hash ("#") sign.
    --step 1 create local temporary table 

    CREATE TABLE #temptbl(

    OrderID int,

    Orderdate datetime,

    amount decimal(10,2)


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

    insert into #temptbl select * from [Order]

    --step-3 select data from #temptabl

    select * from #temptbl

      Modified On Apr-10-2018 05:02:13 AM