set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[STPEditGood] @SysCode int, @Title nvarchar(300), @Code nvarchar(100) output, @BarCode nvarchar(100) output, @Type int, @FstUnit nvarchar(100), @SecUnit nvarchar(100), @UnitRate float, @OrderPoint real, @SalePrice1 money, @SalePrice2 money, @SalePrice3 money, @SalePrice4 money, @SalePrice5 money, @VisitorPer float, @Comment nvarchar(300), @DiscountPer float, @UserPrice money, @GroupId1 Integer, @Groupid2 Integer, @SerialNo bit, @weight real, @term nvarchar(1000) AS DECLARE @Identity int ,@OldRate float; if @groupid1=0 set @groupid1=null if @groupid2=0 set @groupid2=null if @UnitRate=0 set @UnitRate=1 if @Code='' set @code=null if @BarCode='' set @Barcode=null if not @code is null if exists(select goodsyscode from stocktbl where code=@code and goodsyscode<>@SysCode ) begin raiserror (50401,16,1) return 0 end -- Duplicate code if not @Barcode is null if exists(select goodsyscode from stocktbl where Barcode=@Barcode and goodsyscode<>@SysCode ) begin raiserror (50401,16,1) return 0 end -- Duplicate code select @oldRate=unitrate from StockTbl WHERE (GoodSyscode = @sysCode) if @oldrate<>@unitrate if exists(SELECT GoodSysCode, UnitRate FROM invoiceDetailTbl WHERE (UnitRate <> 1 and GoodSysCode=@SysCode)) begin raiserror (50403,16,1) return 0 end -- change in used rate UPDATE StockTbl SET Title = @Title, Code = @Code, BarCode = @BarCode, Type = @Type, FstUnit = @FstUnit, SecUnit = @SecUnit, UnitRate = @UnitRate, OrderPoint = @OrderPoint, SalePrice1 = @SalePrice1, SalePrice2 = @SalePrice2, SalePrice3 = @SalePrice3, SalePrice4 = @SalePrice4, SalePrice5 = @SalePrice5, VisitorPer = @VisitorPer, Comment = @Comment, DiscontPer = @DiscountPer, UserPrice = @UserPrice, GroupID1 = @GroupID1, GroupID2 = @GroupID2, SerialNo = @SerialNo, Weight = @weight,term=@term WHERE (GoodSyscode = @sysCode)