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  real,
    @OrderPoint  real,
    @SalePrice1  money,
    @SalePrice2  money,
    @SalePrice3  money,
    @SalePrice4  money,
    @SalePrice5  money,
    @VisitorPer  money,
    @Comment  nvarchar(300),
    @DiscountPer  real,
    @UserPrice  money,
    @GroupId1  Integer,
    @Groupid2  Integer,
    @SerialNo  bit,
	@weight real,
	@term nvarchar(1000)
	 
AS

    DECLARE 
		@Identity int ;

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 ) 			raiserror (50401,16,1)   -- Duplicate code
if not @Barcode is null	if exists(select goodsyscode from stocktbl where  Barcode=@Barcode and  goodsyscode<>@SysCode ) 			raiserror (50401,16,1)   -- Duplicate code

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)