请教如何通过触发器解决以下问题,谢谢:
当用户前台输入一张入库单时,通过触发器检查物料号与仓位是否匹配。也就是想限制某些规则的物料号只能入指定的仓位,如果不符合要求则不能保存这张单据。现在入库单涉及到两个表:RDRECORD(存储表头信息:日期,仓位,......),rdrecords存储项目信息(存储物料号,入库数量......),现在触发器只第一个条件起作用,检查仓位的那一条不起作用。if exists (select cinvcode cwhcode from inserted where right(cinvcode,1) = 'C' and cwhcode <> '06')begin
print '非法操作,请检查仓位'
rollback transaction
END

解决方案 »

  1.   

    if exists (select cinvcode cwhcode from inserted where right(cinvcode,1) = 'C' and cwhcode <> '06')你少一“,”号 cinvcode cwhcode
      

  2.   

    if exists (select cinvcode,cwhcode from inserted where right(cinvcode,1) = 'C' and cwhcode <> '06')begin
    print '非法操作,请检查仓位'
    rollback transaction
    END
      

  3.   

    还是不行哦,因为CINVCODE和CWHCODE不在同一个表中,语法检查是会说CWHCODE无效字段。
    我这个触发器是建在RDRECORDS表下的,也就是项目表下。
      

  4.   

    if exists (select cinvcode ,cwhcode from inserted a join 
    rdrecord b on a.recordid=b.recordid   where right(cinvcode,1) = 'C' and b.cwhcode <> '06')begin
    print '非法操作,请检查仓位'
    rollback transaction
    ENDrecordid 为rdrecord 的主键