set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[STPCreatePerson] @AccountCode int, @GroupId1 int , @GroupId2 int , @VisitorPer real, @Comment nvarchar(1000), @Introducer nvarchar(1000), @Code bigint =0, @ContactId int, @SalePriceNo int AS if @groupid1=0 set @groupid1=null if @groupid2=0 set @groupid2=null if @contactId=0 set @contactId=null if @Code=0 set @Code=null if not @code is null if exists(select code from persontbl where code=@code) raiserror (50101,16,1) -- Duplicate code INSERT INTO PersonTbl (FK_AccountSysCode, GroupId1, GroupId2, VisitorPer, Comment, Introducer, Code, SalePriceNo, ContactId) VALUES (@AccountCode,@GroupId1,@GroupId2,@VisitorPer,@Comment,@Introducer,@Code,@SalePriceNo,@ContactId)