Tuesday, September 13, 2011

Use of #tmp in Staging tables

there were thousands of records in one staging table., what we want is to keep only one record in it and to test one huge query
Two possible ways
1. copy and paste one record in notepad / clipboard., then delete or truncate entire staging table and insert the copied record into staging --> this looks traditional and time consuming
2. here is my way.

SELECT TOP 1 into #tmp 
FROM   [staging table] 

TRUNCATE TABLE [staging table] 

INSERT INTO [staging table] 
SELECT * 
FROM   #tmp 

Cheers,
Vivek

No comments:

Post a Comment