Friday, November 16, 2012

Create Temporary Table(#Table) in Stored Procedure SQL Server 2005/2008

Here i will show how to create temporary table in Stored Procedure sql server 2005 / 2008

Syntax :



Create table #TableName
(
      --Colun Names
)

Here # is a must when creating Temporary table


EX : 

create proc SP_SPName
(
     // Parameters
)
as
begin

   create table #TempTable

   (
         ID int identity(1,1),
         Name varchar(250),
         Address varchar(500)
   )

 drop #TempTable

End

#TempTable should be dropped else we will get ERROR while executing SP 2nd time..

No comments:

Post a Comment