Tuesday, September 7, 2010

[MSSQL] Temporary Table Implementation

Following implementation of temporary tables which can be used to replace stored procedure.

--checking if exist
IF OBJECT_ID('tempdb..#temp') IS NULL
begin
CREATE TABLE #tempTable1 (
field1 datetime NOT NULL
)
end

--adding data
insert into #tempTable1
select top 1 date from anytable

--do what ever here
select * from #tempTable1

--finaly destroy it
DROP TABLE tempdb..#tempTable1

No comments:

Post a Comment