如何在CASE中使用CASE编写触发器?

时间:2018-03-20 17:00:29

标签: sql sql-server tsql

这是问题:我希望用户在“状态”列中输入值“d%”,值为“完成”,如果输入“p%”,则设置值“处理”

示例代码:

create trigger Update_status
on orders 
after insert, UPDATE
as
    update orders
       case orders.status like
          when 'd%' then set orders.status='done'
          when 'p%' then set orders.status='processing'
       end

1 个答案:

答案 0 :(得分:0)

整个case语句必须是您将字段设置为的值。

create trigger Update_status
on orders 
after insert, UPDATE
as
    update orders
    set order.status = 
       case
           when orders.status like 'd%' then 'done'
           when orders.status like 'p%' then 'processing'
       end