在存储过程中使用DELETE和join

时间:2017-03-25 10:59:59

标签: sql tsql stored-procedures

我试图删除Index.html/Another.html大于3周的任何记录,但我不确定如何实施此操作。问题似乎与连接语法有关。

FeeDueDate

2 个答案:

答案 0 :(得分:0)

您需要指定要删除的表格。例如:

DELETE Fees
    FROM Assignment.dbo.PupilDetails PDetails JOIN
         Assignment.dbo.TuitionFees Fees
         ON PDetails.Pupil_ID = Fees.Pupil_ID
    WHERE FeeDueDate < dateadd(WEEK, -3, getdate());

答案 1 :(得分:0)

请尝试此查询: -

CREATE PROC spAreFeesOverDue 
   AS
  BEGIN 
       DELETE  
       FROM Assignment.dbo.PupilDetails PDetails
       join Assignment.dbo.TuitionFees Fees
       ON PDetails.Pupil_ID = Fees.Pupil_ID
      WHERE FeeDueDate < dateadd(WEEK, -3, getdate())
   END;