I want to be able to use a varable table to delete records from two different tables.
I have this so far
declare @deleted TABLE (Card int)
insert into @deleted
select Card from table1
where recordstatus = 4
delete from table2
from @deleted d
where table2.actionstring like d.card
and Select convert(varchar(8),today,112)
from(Select dateadd(year,-1,getdate())as today)aa
sorry if this is confusing, I am using sql managment 2005
I basically want to be able to get a card number from table one, check to see if the date in table 2 is greater than a year if so delete the record in table 1.
In table two I do not have a field for card number so I need a LIKE statement.
I only have a error in the second part which reads,-
from @deleted d
Thank you in advance
Your second part of the statement is quite confusing indeed…. you’re mixing the DELETE with SELECT in a WHERE clause….. what exactly are you trying to achieve here??
So are you trying to delete all rows from
table2where the theTable2.ActionStringis equal to theCardcolumn in your@deletedtable?? Not quite clear.Also : what’s with the date constraint?? What field in
table2do you want to check against?? What is the condition –<=or>=or what?