Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 retrieve same records in db table as in temp table

Author  Topic 

sharona
Yak Posting Veteran

75 Posts

Posted - 2011-10-20 : 10:44:42
regarding the query below. I would like to retrieve all the records in the #temp_swap table and then delete them from the db table.

I am trying to use a nested query below to see if i can pull those same records from the db table that are in the temp table. Can this be done?

SELECT DISTINCT * FROM #temp_swap T
INNER JOIN
(Select * from SwapDetail S WHERE
QuasarProductCode IN T.QuasarProductCode) as x
ON x.QuasarProductCode=t.QuasarProductCode
ORDER BY x.QuasarProductCode

sharona
Yak Posting Veteran

75 Posts

Posted - 2011-10-20 : 14:11:46
SELECT * FROM EnSIS_Daily_Refresh.#temp_swap T
where t.QuasarProductCode in
(Select QuasarProductCode from SwapDetail )
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-21 : 00:53:53
isnt this enough?
DELETE x FROM #temp_swap T 
INNER JOIN SwapDetail as x
ON x.QuasarProductCode=t.QuasarProductCode


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -