小编典典

如何删除MS SQL数据库中最旧的星期(句号)?

sql

MS SQL 2008R2 Express,我有数据库-
一个带行的表。当数据库大小变为约10GB时,我需要清理此表中最旧的一周(我不知道日期)。您能帮我编写脚本吗?谢谢。

UPD1。有列DateAndTime,所以我在VBA中进行如下查询:

strSQL = "SELECT DateAndTime
                ,TagName
                ,Val
                ,SetPoint
                ,Limit_H
                ,Limit_L
                ,Result 
          FROM dbo.Statistic 
          WHERE DateAndTime  BETWEEN CAST('" & TimeBegin & "' AS datetime) AND CAST( '" & TimeEnd & " ' AS datetime) 
          Order By DateAndTime desc , (CASE WHEN ISNUMERIC(TagName)=1 THEN CAST(CAST(TagName AS float) AS INT)END ) desc"

阅读 168

收藏
2021-04-14

共1个答案

小编典典

那这个呢 -

DELETE YOUR_TABLE
WHERE DATE_COL BETWEEN (SELECT MIN(DATE) FROM YOUR_TABLE) AND (SELECT MIN(DATE) FROM YOUR_TABLE) + 7
2021-04-14