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 2005 Forums
 Transact-SQL (2005)
 Delete from table A based on table B

Author  Topic 

SLM09
Starting Member

31 Posts

Posted - 2009-10-07 : 09:01:09
Could someone tell me if it is possible to delete records from a temp table based on the contents of another table?

So-
#temp1 a b c
#temp2 a c d

DELETE FROM #temp1
WHERE #temp1.data = #temp2.data

Or something along those lines?

Thanks

Sachin.Nand

2937 Posts

Posted - 2009-10-07 : 09:07:29
Delete T1 from #temp1 T1
INNER JOIN #temp2 On T1.data=T2.data



PBUH
Go to Top of Page

SLM09
Starting Member

31 Posts

Posted - 2009-10-07 : 09:40:19
Sorry, I think I did my usual horrible attempt at an explanation.

#temp1
col1 col2 col3
a 1 ...
b 2 ...
c 3 ...

#temp2
col1 col2 col3
a 4 ...
c 5 ...
d 6 ...

#temp1 has a record where col1 'a' also appears in #temp2. I want to delete the entire row from #temp1 in this case.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2009-10-07 : 09:43:05
Did you try my solution?Please take a backup before u do it.Just in case :)

PBUH
Go to Top of Page

SLM09
Starting Member

31 Posts

Posted - 2009-10-07 : 11:25:08
Thanks Idera, it did work! I misunderstood the code when I first looked at it, that was my bad. :P

Thanks again!
Go to Top of Page
   

- Advertisement -