Hi
I writ a query but when I execute it, prompt me:
Msg 248, Level 16, State 1, Line 13
The conversion of the nvarchar value '7111000101' overflowed an int column.
The statement has been terminated.
Msg 547, Level 16, State 0, Line 15
The INSERT statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK_tblAccount_tblAccount". The conflict occurred in database "Accountingdb", table "dbo.tblAccount".
The statement has been terminated.
The source is:
declare @vendor_id varchar(50)
DECLARE vendor_cursor CURSOR FOR
select code from publicdata.dbo.tblcompany where code <> 1
--ORDER BY s1
--HAVING s1=4
OPEN vendor_cursor
FETCH NEXT FROM vendor_cursor INTO @vendor_id
WHILE @@FETCH_STATUS = 0
begin
insert into Accountingdb.dbo.tblAccount(AccCode, CompanyID, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle)
Select AccCode,@vendor_id, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle from Accountingdb.dbo.tblAccount where CompanyID=1 and AccCode=0
insert into Accountingdb.dbo.tblAccount(AccCode, CompanyID, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle)
Select AccCode, @vendor_id, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle from Accountingdb.dbo.tblAccount where CompanyID=1 and LEN(AccCode)=1 and AccCode>0
insert into Accountingdb.dbo.tblAccount(AccCode, CompanyID, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle)
Select AccCode, @vendor_id, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle from Accountingdb.dbo.tblAccount where CompanyID=1 and LEN(AccCode)=3
insert into Accountingdb.dbo.tblAccount(AccCode, CompanyID, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle)
Select AccCode, @vendor_id, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle from Accountingdb.dbo.tblAccount where CompanyID=1 and LEN(AccCode)=6
insert into Accountingdb.dbo.tblAccount(AccCode, CompanyID, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle)
Select AccCode, @vendor_id, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle from Accountingdb.dbo.tblAccount where CompanyID=1 and LEN(AccCode)=8
insert into Accountingdb.dbo.tblAccount(AccCode, CompanyID, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle)
Select AccCode, @vendor_id, AccName, AccGroup, AccLevel, Lowest, Kind, debit, NumberCtl, ValueCtl, CompanyCtl, CostCenterCtl, TimeCtl, EntityCtl, ProfitLooseType, CostCenter2Ctl, remainCycle from Accountingdb.dbo.tblAccount where CompanyID=1 and LEN(AccCode)=10
print @vendor_id
FETCH NEXT FROM vendor_cursor INTO @vendor_id
END
CLOSE vendor_cursor;
DEALLOCATE vendor_cursor;