简体   繁体   English

SQL更新触发到系统时间> 20分钟的列时间

[英]SQL update trigger to when system time is > 20 minutes of column time

I am very new to SQL Triggers. 我是SQL触发器的新手。

I have a column "Status_ID" where it gets updated by different values. 我有一列“ Status_ID”,其中它通过不同的值进行更新。 My Trigger should flag a column "Alarm_Late_Pickup" whenever the "Status_ID" is not updated to value "4" before 20 minutes of the current time, the next step is to flag another column "Late_Pickup" when the "Status_ID" is not set to "5" when the current time is Larger then the "Pickup_Time" column. 每当“ Status_ID”在当前时间的20分钟之前未更新为值“ 4”时,我的触发器应标记“ Alarm_Late_Pickup”列,下一步是在未将“ Status_ID”设置为“ Late_Pickup”时标记另一列“ Late_Pickup”当前时间大于“ Pickup_Time”列时为“ 5”。

I would say that you need an event schedule rather than a trigger. 我要说的是,您需要一个事件时间表而不是触发器。 But, in SQL Server, you can do what you want with a computed column or view: 但是,在SQL Server中,您可以使用计算列或视图来执行所需的操作:

ALTER TABLE 
    t
ADD 
    IsFinished AS (CASE 
                        WHEN 
                            (Pickup_Time < DATEADD(MINUTE, -20, GETDATE()) 
                            OR
                            (Delivery_Time < DATEADD(MINUTE, -20, GETDATE()))) THEN 1 
                        ELSE 0 END)

This adds a column to the table that is recalculated each time it is used. 这会向表中添加一列,该列在每次使用时都会重新计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM