isnull(@hp_id,'')
isnull(@storage,'')
if @hp_id='' or @storage='' then  print '该货品不存在'
这样

解决方案 »

  1.   

    你忘记了为null的情况
    if @hp_id is null or @hp_id='' then print '该货品不存在'
    if @storage is null or @storage='' then print '该货品不存在'
      

  2.   

    if isnull(@hp_id,'')='' or isnull(@storage,'')='' or ltrim(rtrim(@hp_id))='' or ltrim(rtrim(@storage))='' then  print '该货品不存在'
      

  3.   

    if isnull(@hp_id,'')='' or isnull(@storage,'')='' then  print '该货品不存在'
      

  4.   

    if IsNull(@hp_id,'')='' or IsNull(@storage,'')='' then  print '该货品不存在'
      

  5.   

    ecol() 你好,我试了你的代码可是它报错“关键字 "then"附近语法错误啊”
      

  6.   

    谢谢大家帮助,可是为什么总是出来“关键字 "then"附近语法错误啊”
    我把整个触发器的代码贴出来吧
    CREATE TRIGGER DELIVER ON [dbo].[Delivery] 
    FOR INSERT
    AS
    IF @@ROWCOUNT=0 RETURN
    DECLARE @ORDERID NVARCHAR(20),@AMOUNT INT,@HP_ID NVARCHAR(10)
    DECLARE @STORAGE NVARCHAR(50)
    SELECT @ORDERID=销售订单编号,@STORAGE=出货仓 from inserted
    select @HP_ID=货品编号,@amount=数量 from deliveryorderdetail where 订单编号=@orderid
    BEGIN
    if IsNull(@hp_id,'')='' or IsNull(@storage,'')='' then  print '该货品不存在'×××
    UPDATE PRODUCTSTORAGE set KC=KC-@AMOUNT where hp_id=@hp_id and ck_name=@storage
    END
      

  7.   

    sql server中if 无then, oracle才有