我有一个 table 在那一行是 PublishingStatus,它是 Approved,Pending,Rejected

I have a table in that one row is PublishingStatus which is as Approved,Pending,Rejected

table 我将其保存为 Approve=1,Pending=0,Rejected=2,另一行是 ApprovalDeadlineDate。如果批准截止日期已过(超过今天的日期),那么它应该自动更新并且发布状态应该被批准为“1”。

我正在使用的查询如下

update Tbl_Documents set
  PublishingStatus = case when Convert(nvarchar(20),cast(ApprovalDeadlinedate as date),105) < Convert(nvarchar(20),cast(SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30') as date),105)
    then '1' else '0' end

试试这个。

UPDATE Tbl_Documents SET PublishingStatus = '1'
WHERE CAST(ApprovalDeadlinedate AS DATE) < GETDATE()
AND PublishingStatus = '0'