鉴于以下内容
Clients Table
--------------
Id int
DaysToLive int
和
CallRecords Table
-----------------
ClientId int
Reported bit
ReportedTime DateTime2
我试图删除CallRecords table
中的所有记录,其ReportTime
列DaysToLive
早于Clients Table
以下是在后台服务(客户端的客户端)中运行,但是我试图将其转换为原始sql以在sql代理程序预定作业中使用
Delete from CallRecords where ClientId = {0} and Reported = 1 and ReportedTime < GETDATE() - {1}
但是,我不确定如何为join
答案 0 :(得分:1)
不清楚日期条件,但
试试这样:
DELETE cr
FROM CallRecords cr
INNER JOIN Clients c
ON c.Id =cr.ClientId
Where cr.Reported = 1 AND <the date condition>.