触发器后插入无法正常工作想要在触发器后插入中更新 table

Insert after trigger not working properly want to Update table in inset after trriger

我有一个 table 并在进行一些计算和更新列的那个上触发。

我想更新输入模式字段,想在 table 中设置 0 和 1 天。 我编写了以下代码但无法正常工作。

WITH CTE AS
(
    SELECT 
        ROW_NUMBER() OVER (ORDER BY Convert(datetime, el.M_Edatetime)) AS ROW,
        el.LogId 
    FROM 
        Essl_logdata el 
    INNER JOIN
        Inserted i ON el.EnrollNo = i.EnrollNo 
                   AND el.M_Edatetime = i.M_Edatetime
    WHERE 
        el.EnrollNo = @INS 
        AND Convert(Date, el.M_Edatetime) = Convert(date, @M_datetime)
)
UPDATE Essl_logdata 
SET InOutMode = '0' 
FROM CTE 
WHERE ROW%2 <> 0 AND Essl_logdata.LogId = CTE.LogId;

WITH CTE AS
(
    SELECT 
        ROW_NUMBER() OVER (ORDER BY COnvert(datetime, el.M_Edatetime)) AS ROW,
        el.LogId 
    FROM 
        Essl_logdata el 
    INNER JOIN
        Inserted i ON el.EnrollNo = i.EnrollNo 
                   AND el.M_Edatetime = i.M_Edatetime 
    WHERE
        el.EnrollNo = @INS 
        AND Convert(Date, el.M_Edatetime) = Convert(date, @M_datetime)
)
UPDATE Essl_logdata 
SET InOutMode = '1' 
FROM CTE 
WHERE ROW%2 = 0 AND Essl_logdata.LogId = CTE.LogId;

预期结果如下

触发器中的当前查询显示结果如下。

WITH CTE AS
        (
            SELECT ROW_NUMBER() OVER(PARTITION BY COnvert(date,M_Edatetime),EnrollNo ORDER BY COnvert(datetime,M_Edatetime))AS ROW,Logid,M_Edatetime,EnrollNo FROM Essl_logdata  group by M_Edatetime,Logid,EnrollNo
        )           
        Update Essl_logdata set InOutMode = '1' FROM CTE WHERE ROW%2 = 0 and Essl_logdata.LogId = CTE.LogId;

WITH CTE AS
        (
            SELECT ROW_NUMBER() OVER(PARTITION BY COnvert(date,M_Edatetime),EnrollNo ORDER BY COnvert(datetime,M_Edatetime))AS ROW,Logid,M_Edatetime,EnrollNo FROM Essl_logdata  group by M_Edatetime,Logid,EnrollNo
        )       
        Update Essl_logdata set InOutMode = '0' FROM CTE WHERE ROW%2 <> 0 and Essl_logdata.LogId = CTE.LogId;

我发现这个解决方案是解决方法