您好我需要能够搜索一年前的记录然后将其删除。我有这个脚本允许我根据另一个表给出的日期从一个表中删除记录,但是我需要为此添加代码,以便我能够从与CardID相关的不同表中删除记录。我需要删除的表是table11,主键是CardID。
我想我需要一个左联盟,但我不确定如何去做。
DECLARE @deleted TABLE (Card INT)
INSERT INTO @deleted
SELECT Card FROM table9
WHERE recordstatus = 4
DELETE table9
FROM @deleted d, table51
WHERE table51.ActionString LIKE '%' + CAST(d.card AS VARCHAR(20))+ '%'
AND table51.AuditDate <= (SELECT CONVERT(VARCHAR(8),today,112) FROM(SELECT DATEADD(YEAR,-1,GETDATE()) AS today)aa)
AND table09.Card = d.card
提前致谢,希望你能提供帮助。