用于更新表的SQL触发器

时间:2015-06-30 09:27:33

标签: sql-server triggers sql-server-2012

我有3张表如下:

  • action:ID,注意
  • action_type:ID,日期,ticket_ID,类型
  • action:ID,类型,名称

每次将新记录插入ticket.Note时,我都需要将action.dateaction_type.nameticket连接起来。但仅限于某些行为类型。

所以请考虑以下情况:

  • action是:0056,someNote
  • action_type是:001234,06/30/2015 14:00:22,0056,4
  • #0056是:004,4,创建

我需要ticket.Note someNote;06-30-2015 createincorrect 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 错误:

zIndex

1 个答案:

答案 0 :(得分:2)

我认为你想要实现的是:

file.txt