SQL 触发更新 table

SQL trigger for updating a table

我有3个表如下:

每次将新记录插入 action 时,我都需要将 ticket.Noteaction.dateaction_type.name 连接起来。但仅适用于某些操作类型。

所以采取以下情况:

我需要 #0056 ticket.Note 才能成为 someNote;06-30-2015 create

我试过下面的代码,但我得到 incorrect syntax 错误:

CREATE TRIGGER trg_notes
ON action
AFTER INSERT AS
BEGIN
    UPDATE ticket
    SET
    Note = 
        Note + 
        ';' + 
        CONVERT(VARCHAR(10),(select date from inserted),110) + 
        (select 
             t.name 
         from 
             action_type t 
         LEFT OUTER JOIN inserted i ON i.action = t.ID 
         WHERE 
             i.action = t.ID)
    where 
        ticket.ID = inserted.ticket_ID
    AND 
        (inserted.action = 4 
         OR 
         inserted.action = 7 
         OR 
         inserted.action = 8 
         OR 
         inserted.action = 11 
         OR 
         inserted.action = 12)
END

我想你想要实现的是:

CREATE TRIGGER trg_notes
ON action
AFTER INSERT AS
BEGIN
    UPDATE  t
    SET     t.Note = t.Note + ';' + CONVERT(VARCHAR(10),i.[date],110) + at.name
    FROM    inserted i
            inner join tickets t ON i.ticket_ID = t.ID
            inner join action_type at ON i.[type] = at.[type]
    WHERE   inserted.[type] IN(4,7,8,11,12) 
END