CREATE trigger tr_news_hq on news_hq
instead of insert
as
--if i.ts_zd='' begin
insert into news_hq
select ts_pm,ts_gg,ts_cz,ts_gc,ts_jg1,ts_jg2,ts_jg,ts_jg-(select top 1 ts_jg from news_hq where ts_pm=i.ts_pm and ts_gg=i.ts_gg and ts_cs=i.ts_cs and ts_cz=i.ts_cz and ts_gc=i.ts_gc  order by ts_sj desc),ts_cs,ts_sj,ts_bz,ts_bj,ts_bb
from inserted i
end以上触发器 我想判断  ts_zd 是否为空  如果为空就执行下面的语句。不为空就不执行了

解决方案 »

  1.   

    CREATE trigger tr_news_hq on news_hq
    instead of insert
    as
    if exists(select 1 from inserted where  ts_zd is null)    /*在此判断*/
    begin
    insert into news_hq
    select ts_pm,ts_gg,ts_cz,ts_gc,ts_jg1,ts_jg2,ts_jg,ts_jg-(select top 1 ts_jg from news_hq where ts_pm=i.ts_pm and ts_gg=i.ts_gg and ts_cs=i.ts_cs and ts_cz=i.ts_cz and ts_gc=i.ts_gc  order by ts_sj desc),ts_cs,ts_sj,ts_bz,ts_bj,ts_bb
    from inserted i
    end
      

  2.   

    --判断加入
    if exists(Select * from inserted where ts_zd='')
      

  3.   

    if exists(select 1 from inserted where  ts_zd is null or ts_zd='')