|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
数据库名: UFDATA_002_2007
应收应付数据, DATA2_AP
错误信息:
-2147217873
违反了 PRIMARY KEY 约束 'PK_VoucherNumber'。不能在对象 'VoucherNumber' 中插入重复键。
执行如下语句时出错:
--预置单据编号
DECLARE @bRemote VARCHAR(10)
DECLARE @RemoteID Varchar(2)
DECLARE @ID int
Set @bRemote=(SELECT Upper(cValue) FROM Accinformation Where cName='bRemote')
IF @bRemote ='TRUE'
Set @RemoteID=(SELECT Isnull(cValue,'') FROM Accinformation Where cName='cID')
ELSE
Set @RemoteID=''
IF NOT EXISTS (Select CardNumber From VoucherNumber Where AppName='应收' and CardNumber='R0')
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName) values('应收','R0','其他应收单')
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AR' and cType='R0')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('R0',@ID)
END
IF NOT EXISTS (Select CardNumber From VoucherNumber Where AppName='应付' and CardNumber='P0')
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName) values('应付','P0','其他应付单')
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AP' and cType='P0')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('P0',@ID)
END
IF NOT EXISTS (Select CardNumber From VoucherNumber Where AppName='应收' and CardNumber='RR')
IF @bRemote='TRUE'
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName,iSize,dStartDate,Prefix1,Prefix1Len)
values('应收','RR','收款单',10,getdate(),'远程号',2)
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AR' and cType='R')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('RR',@ID)
END
ELSE
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName) values('应收','RR','收款单')
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AR' and cType='R')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('RR',@ID)
END
IF NOT EXISTS (Select CardNumber From VoucherNumber Where AppName='应收' and CardNumber='RP')
IF @bRemote='TRUE'
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName,iSize,dStartDate,Prefix1,Prefix1Len)
values('应收','RP','付款单',10,getdate(),'远程号',2)
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AR' and cType='P')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('RP',@ID)
END
ELSE
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName) values('应收','RP','付款单')
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AR' and cType='P')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('RP',@ID)
END
IF NOT EXISTS (Select CardNumber From VoucherNumber Where AppName='应付' and CardNumber='PP')
IF @bRemote='TRUE'
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName,iSize,dStartDate,Prefix1,Prefix1Len)
values('应付','PP','付款单',10,getdate(),'远程号',2)
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AP' and cType='P')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('PP',@ID)
END
ELSE
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName) values('应付','PP','付款单')
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AP' and cType='P')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('PP',@ID)
END
IF NOT EXISTS (Select CardNumber From VoucherNumber Where AppName='应付' and CardNumber='PR')
IF @bRemote='TRUE'
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName,iSize,dStartDate,Prefix1,Prefix1Len)
values('应付','PR','收款单',10,getdate(),'远程号',2)
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AP' and cType='R')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('PR',@ID)
END
ELSE
BEGIN
insert into VoucherNumber (AppName,CardNumber,CardName) values('应付','PR','收款单')
set @ID=(select Max(iCancelNo) From Ap_CancelNo Where cFlag='AP' and cType='R')
IF @ID is not null insert into VoucherHistory (CardNumber,cNumber) values('PR',@ID)
END |
|