1、不必优化了
2、if 1 and 2 and 3 or 4 简单的加个4可以的,清楚点就写成if (1 and 2 and 3) or 4

解决方案 »

  1.   

    1、Try:
    if exists (select 1 from inserted
       where FItemClassID=4 and len(FNumber)-len(replace(FNumber,'.',''))<4 ) 
    and (SELECT count(distinct FItemClassID)
    FROM t_ItemClass WHERE (FItemClassID = 4 or FItemClassID = 1234567) AND (FGRType = 0)) =2
    begin
    ...
    end
    这个看起来好像简化了,但是效率提高还是降低就很难说
      

  2.   

    (SELECT count(distinct FItemClassID)
    FROM t_ItemClass WHERE (FItemClassID = 4 or FItemClassID = 1234567) AND (FGRType = 0)) =2
    ——————————————————
    我觉得还是楼主原来的写法好一些,那样看起来更清晰一些。性能也不会差的
      

  3.   

    create trigger tr_t_item_update
    on t_item
    for update
    as
    if exists (select 1 from inserted
       where FItemClassID=4 and len(FNumber)-len(replace(FNumber,'.',''))<4 )
     and (SELECT count(distinct FItemClassID)
    FROM t_ItemClass WHERE (FItemClassID in(1234567,4) AND (FGRType = 0))>1begin
       RAISERROR ('不允许此类添加',16, 1)  
       ROLLBACK TRANSACTION
    end