/***创建触发器,在用户表上检测如果用户表有更新则触发update并处理***/
CREATE TRIGGER U_P_D_OUSR_SLIC ON [dbo].[OUSR] --创建触发器
FOR UPDATE --用于 ADD/UPDATE/DELETE 操作时触发
AS
BEGIN
----向临时表中插入数据
DECLARE @AliasUpd NVARCHAR(254) = NULL
DECLARE @TB01 TABLE ([DateForm] DATE,[DateTo] DATE,[AliasUpd] NVARCHAR(254));
INSERT INTO @TB01
SELECT '2023/3/7','2023/4/5',N'htRf7+PE3mItgDA16BdlOxq5MQj44XTt' UNION ALL
SELECT '2023/4/5','2023/5/5',N'htRf7+PE3mLzGzDPZfHDEgEPlwLGGxyN'
--从临时表 @TB01中取数
DECLARE @DateNow DATE = GETDATE()
DECLARE @AliasUpd_Tmp1 NVARCHAR(254) = (SELECT T0.AliasUpd FROM @TB01 T0 WHERE @DateNow >= T0.DateForm AND @DateNow < T0.DateTo)
SET @AliasUpd = @AliasUpd_Tmp1
END
IF(@AliasUpd IS NOT NULL)--更新表
BEGIN
UPDATE T0 SET T0.AliasUpd = @AliasUpd FROM [SBO-COMMON].[dbo].[SLIC] T0
END
END