你忘记了为null的情况 if @hp_id is null or @hp_id='' then print '该货品不存在' if @storage is null or @storage='' then print '该货品不存在'
if isnull(@hp_id,'')='' or isnull(@storage,'')='' or ltrim(rtrim(@hp_id))='' or ltrim(rtrim(@storage))='' then print '该货品不存在'
if isnull(@hp_id,'')='' or isnull(@storage,'')='' then print '该货品不存在'
if IsNull(@hp_id,'')='' or IsNull(@storage,'')='' then print '该货品不存在'
ecol() 你好,我试了你的代码可是它报错“关键字 "then"附近语法错误啊”
谢谢大家帮助,可是为什么总是出来“关键字 "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
if @hp_id is null or @hp_id='' then print '该货品不存在'
if @storage is null or @storage='' then print '该货品不存在'
我把整个触发器的代码贴出来吧
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