JR1204
Starting Member
7 Posts |
Posted - 2014-03-27 : 09:14:18
|
I'm trying to enhance a stored procedure that takes accounts payable data from one database and inserts into Dynamics GP company database. The first half was working (The execute statement for taPMTransactionInsert), and that creates the record in the 'main' transaction screen in GP. However, I want to use the second half of the procedure (taPMDistributionInsert) to create the distribution lines in the detail screen in GP. Please help!!All the variables appear to be accounted for, but i am receiving this error:Error converting data type varchar to numeric. 'BOAUS', 'AP032714.31726' This is the CODE: EXECUTE @RCOUT = BOAUS.[dbo].[taPMDistributionInsert] ' 1', ' ', ' ', ' 0', '0.00000', '3200.00000', ' 6', ' 0', ' 0', ' 0', ' 0', ' ', ' ', '0.0000000', '01/01/1900', '01/01/1900', ' 0', ' ', '0.00000', '0.00000', ' 0' , @O_iErrorStateOUT OUTPUT , @oErrStringOUT OUTPUT...This is the Parm: @RCOUT int output, @O_iErrorStateOUT int output, @oErrStringOUT nvarchar(255) outputHERE IS THE CODEUSE [Operations6]GO/****** Object: StoredProcedure [dbo].[webAPExpensClaimUploadHDR] Script Date: 3/27/2014 7:54:24 AM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[webAPExpensClaimUploadHDR] @DBSRC nvarchar(15), @BATCHNO nvarchar(50), @RC int outputasdeclare @SQL nvarchar(max)declare @ParmDef nvarchar(max)DECLARE @I_vBACHNUMB char(15)=@BatchNODECLARE @I_vVCHNUMWK char(17)=''DECLARE @I_vVENDORID char(15)=''DECLARE @I_vDOCNUMBR char(20)=''DECLARE @I_vDOCTYPE smallint=0DECLARE @I_vDOCAMNT numeric(19,5)=0DECLARE @I_vDOCDATE datetime=convert(nvarchar(10), getdate(), 101)DECLARE @I_vPSTGDATE datetime=convert(nvarchar(10), getdate(), 101)DECLARE @I_vVADCDTRO char(15)=''DECLARE @I_vVADDCDPR char(15)=''DECLARE @I_vPYMTRMID char(20)=''DECLARE @I_vTAXSCHID char(15)=''DECLARE @I_vDUEDATE datetime='1/1/1900'DECLARE @I_vDSCDLRAM numeric(19,5)=0DECLARE @I_vDISCDATE datetime='1/1/1900'DECLARE @I_vPRCHAMNT numeric(19,5)=0DECLARE @I_vCHRGAMNT numeric(19,5)=0DECLARE @I_vCASHAMNT numeric(19,5)=0DECLARE @I_vCAMCBKID char(15)=''DECLARE @I_vCDOCNMBR char(20)=''DECLARE @I_vCAMTDATE datetime='1/1/1900'DECLARE @I_vCAMPMTNM char(20)=''DECLARE @I_vCHEKAMNT numeric(19,5)=0DECLARE @I_vCHAMCBID char(15)=''DECLARE @I_vCHEKDATE datetime='1/1/1900'DECLARE @I_vCAMPYNBR char(20)=''DECLARE @I_vCRCRDAMT numeric(19,5)=0DECLARE @I_vCCAMPYNM char(20)=''DECLARE @I_vCHEKNMBR char(20)=''DECLARE @I_vCARDNAME char(15)=''DECLARE @I_vCCRCTNUM char(20)=''DECLARE @I_vCRCARDDT datetime='1/1/1900'DECLARE @I_vCHEKBKID char(15)=''DECLARE @I_vTRXDSCRN char(30)=''DECLARE @I_vTRDISAMT numeric(19,5)=0DECLARE @I_vTAXAMNT numeric(19,5)=0DECLARE @I_vFRTAMNT numeric(19,5)=0DECLARE @I_vTEN99AMNT numeric(19,5)=0DECLARE @I_vMSCCHAMT numeric(19,5)=0DECLARE @I_vPORDNMBR char(20)=''DECLARE @I_vSHIPMTHD char(15)=''DECLARE @I_vDISAMTAV numeric(19,5)=0DECLARE @I_vDISTKNAM numeric(19,5)=0DECLARE @I_vAPDSTKAM numeric(19,5)=0DECLARE @I_vMDFUSRID char(15)=''DECLARE @I_vPOSTEDDT datetime='1/1/1900'DECLARE @I_vPTDUSRID char(15)=''DECLARE @I_vPCHSCHID char(15)=''DECLARE @I_vFRTSCHID char(15)=''DECLARE @I_vMSCSCHID char(15)=''DECLARE @I_vPRCTDISC numeric(19,2)=0DECLARE @I_vTax_Date datetime='1/1/1900'DECLARE @I_vCURNCYID char(15)=''DECLARE @I_vXCHGRATE numeric(19,7)=0DECLARE @I_vRATETPID char(15)=''DECLARE @I_vEXPNDATE datetime='1/1/1900'DECLARE @I_vEXCHDATE datetime='1/1/1900'DECLARE @I_vEXGTBDSC char(30)=''DECLARE @I_vEXTBLSRC char(50)=''DECLARE @I_vRATEEXPR smallint=0DECLARE @I_vDYSTINCR smallint=0DECLARE @I_vRATEVARC numeric(19,7)=0DECLARE @I_vTRXDTDEF smallint=0DECLARE @I_vRTCLCMTD smallint=0DECLARE @I_vPRVDSLMT smallint=0DECLARE @I_vDATELMTS smallint=0DECLARE @I_vTIME1 datetime='1/1/1900'DECLARE @I_vBatchCHEKBKID char(15)=''DECLARE @I_vCREATEDIST smallint=0DECLARE @I_vRequesterTrx smallint=0DECLARE @I_vUSRDEFND1 char(50)=''DECLARE @I_vUSRDEFND2 char(50)=''DECLARE @I_vUSRDEFND3 char(50)=''DECLARE @I_vUSRDEFND4 varchar(8000)=''DECLARE @I_vUSRDEFND5 varchar(8000)=''DECLARE @O_iErrorState int=0DECLARE @oErrString varchar(255)=''set @RC=0set @I_vDOCTYPE=1declare Batchcur cursor for select employid, Amount, ClaimName from webparamExpenseClaimhorwhere apbatchno = @batchnoand DBSRC = @DBSRCand donotpostap = 0open batchcur fetch batchcur into @I_vVendorID, @I_vDOCAMNT, @I_vTRXDSCRNwhile @@fetch_status = 0beginset @I_vChrgamnt = @I_vDOCAMNTset @I_vPRCHAMNT = @I_vDOCAMNT-- DECLARE @I_vInc_Dec tinyintDECLARE @O_iPMNPYNBR varchar(21)---- TODO: Remove hardcoded BOAUSEXECUTE @RC = boaus.[dbo].[taGetPMNextPaymentNumber] 1 ,@O_iPMNPYNBR OUTPUT ,@O_iErrorState OUTPUTset @I_vdocnumbr = @O_iPMNPYNBRset @I_vVCHNUMWK=@O_iPMNPYNBRset @SQL='EXECUTE @RCOUT = ' + rtrim(@dbsrc) + '.[dbo].[taPMTransactionInsert] ' + '''' +@I_vBACHNUMB+''', '+'''' +@I_vVCHNUMWK+''', '+'''' +@I_vVENDORID+''', '+'''' +@I_vDOCNUMBR+''', '+'''' +str(@I_vDOCTYPE)+''', '+'''' + convert(varchar(50),@I_vDOCAMNT)+''', '+'''' +convert(nvarchar(10), @I_vDOCDATE, 101) +''', '+'''' +convert(nvarchar(10), @I_vPSTGDATE, 101) +''', '+'''' +@I_vVADCDTRO+''', '+'''' +@I_vVADDCDPR+''', '+'''' +@I_vPYMTRMID+''', '+'''' +@I_vTAXSCHID+''', '+'''' +convert(nvarchar(10), @I_vDUEDATE, 101) +''', '+'''' +str(@I_vDSCDLRAM)+''', '+'''' +convert(nvarchar(10), @I_vDISCDATE, 101) +''', '+'''' +convert(varchar(50),@I_vPRCHAMNT)+''', '+'''' +convert(varchar(50),@I_vCHRGAMNT)+''', '+'''' +convert(varchar(50),@I_vCASHAMNT)+''', '+'''' +@I_vCAMCBKID+''', '+'''' +@I_vCDOCNMBR+''', '+'''' +convert(nvarchar(10), @I_vCAMTDATE, 101) +''', '+'''' +@I_vCAMPMTNM+''', '+'''' +convert(varchar(50),@I_vCHEKAMNT)+''', '+'''' +@I_vCHAMCBID+''', '+'''' +convert(nvarchar(10), @I_vCHEKDATE, 101) +''', '+'''' +@I_vCAMPYNBR+''', '+'''' +convert(varchar(50),@I_vCRCRDAMT)+''', ' +'''' +@I_vCCAMPYNM+''', '+'''' +@I_vCHEKNMBR+''', '+'''' +@I_vCARDNAME+''', '+'''' +@I_vCCRCTNUM+''', '+'''' +convert(nvarchar(10), @I_vCRCARDDT, 101) +''', '+'''' +@I_vCHEKBKID+''', '+'''' +@I_vTRXDSCRN+''', ' +'''' +convert(varchar(50),@I_vTRDISAMT)+''', '+'''' +convert(varchar(50),@I_vTAXAMNT)+''', '+'''' +convert(varchar(50),@I_vFRTAMNT)+''', '+'''' +convert(varchar(50),@I_vTEN99AMNT)+''', '+'''' +convert(varchar(50),@I_vMSCCHAMT)+''', '+'''' +@I_vPORDNMBR+''', '+'''' +@I_vSHIPMTHD+''', '+'''' +str(@I_vDISAMTAV)+''', '+'''' +str(@I_vDISTKNAM)+''', '+'''' +str(@I_vAPDSTKAM)+''', '+'''' +@I_vMDFUSRID+''', '+'''' +convert(nvarchar(10), @I_vPOSTEDDT, 101) +''', '+'''' +@I_vPTDUSRID+''', '+'''' +@I_vPCHSCHID+''', '+'''' +@I_vFRTSCHID+''', '+'''' +@I_vMSCSCHID+''', '+'''' +str(@I_vPRCTDISC)+''', '+'''' +convert(nvarchar(10), @I_vTax_Date, 101) +''', '+'''' +@I_vCURNCYID+''', '+'''' +convert(varchar(50), @I_vXCHGRATE)+''', '+'''' +@I_vRATETPID+''', '+'''' +convert(nvarchar(10), @I_vEXPNDATE, 101) +''', '+'''' +convert(nvarchar(10), @I_vEXCHDATE, 101) +''', '+'''' +@I_vEXGTBDSC+''', '+'''' +@I_vEXTBLSRC+''', '+'''' +str(@I_vRATEEXPR)+''', '+'''' +str(@I_vDYSTINCR)+''', '+'''' +str(@I_vRATEVARC)+''', '+'''' +str(@I_vTRXDTDEF)+''', '+'''' +str(@I_vRTCLCMTD)+''', '+'''' +str(@I_vPRVDSLMT)+''', '+'''' +str(@I_vDATELMTS)+''', '+'''' +convert(nvarchar(10), @I_vTIME1, 101) +''', ' +'''' +@I_vBatchCHEKBKID+''', ' +'''' +str(@I_vCREATEDIST)+''', '+'''' +str(@I_vRequesterTrx)+''', '+'''' +@I_vUSRDEFND1+''', '+'''' +@I_vUSRDEFND2+''', '+'''' +@I_vUSRDEFND3+''', '+'''' +@I_vUSRDEFND4+''', '+'''' +@I_vUSRDEFND5+''', @O_iErrorStateOUT OUTPUT , @oErrStringOUT OUTPUT'set @ParmDef=N'@RCOUT int OUTPUT, @O_iErrorStateOUT int OUTPUT, @oErrStringOUT NVarchar(255) OUTPUT'EXECUTE sp_executesql @SQL, @ParmDef, @RCOUT=@RC OUTPUT, @O_iErrorStateOUT =@O_iErrorState, @oErrStringOUT =@oErrStringif @RC<> 0 break--Need to call this procedure twice: once for debit, once for credit.DECLARE @I_vACTINDX int=0 -- This will come from the posting config paramDECLARE @I_vDEBITAMT numeric(19,5)=0DECLARE @I_vCRDTAMNT numeric(19,5)=0DECLARE @I_vDISTTYPE smallint=0DECLARE @I_vCURRNIDX smallint=0DECLARE @I_vDECPLCUR int=0DECLARE @I_vTRXSORCE char(13)=''DECLARE @I_vDistRef char(30)=''DECLARE @I_vEXGTBLID char(15)=''DECLARE @I_vORDBTAMT numeric(9,5)=0DECLARE @I_vORCRDAMT numeric(9,5)=0set @I_vDOCTYPE=1set @I_vVENDORID=''set @I_vVCHNUMWK=''set @I_vCURNCYID=''set @I_vPTDUSRID=''set @I_vRATETPID=''set @I_vXCHGRATE=0set @I_vEXCHDATE='1/1/1900'set @I_vEXPNDATE='1/1/1900'set @I_vTIME1='1/1/1900'set @I_vRTCLCMTD=0set @I_vDEBITAMT=0set @O_iErrorState=0set @oErrString=''set @RC = 0set @O_iErrorState=0set @oErrString=''Set @I_vDISTTYPE=6set @I_vCRDTAMNT=@I_vDOCAMNTset @SQL= 'EXECUTE @RCOUT = ' +rtrim(@dbsrc) + '.[dbo].[taPMDistributionInsert] ' + '''' +str(@I_vDOCTYPE)+''', '+'''' +@I_vVCHNUMWK+''', '+'''' +@I_vVENDORID+''', '+'''' +str(@I_vACTINDX)+''', '+'''' +convert(varchar(50),@I_vDEBITAMT)+''', '+'''' +convert(varchar(50),@I_vCRDTAMNT)+''', '+'''' +str(@I_vDISTTYPE)+''', '+'''' +str(@I_vCURRNIDX)+''', '+'''' +str(@I_vDECPLCUR)+''', '+'''' +str(@I_vTRXSORCE)+''', '+'''' +str(@I_vDistRef)+''', '+'''' +@I_vPTDUSRID+''', '+'''' +@I_vRATETPID+''', '+'''' +convert(nvarchar(50), @I_vXCHGRATE)+''', '+'''' +convert(nvarchar(10), @I_vEXCHDATE, 101) +''', '+'''' +convert(nvarchar(10), @I_vEXPNDATE, 101) +''', '+'''' +str(@I_vEXGTBLID)+''', '+'''' +@I_vRATETPID+''', '+'''' +convert(varchar(50),@I_vORDBTAMT)+''', '+'''' +convert(varchar(50),@I_vORCRDAMT)+''', '+'''' +str(@I_vRTCLCMTD)+''' , @O_iErrorStateOUT OUTPUT , @oErrStringOUT OUTPUT'set @ParmDef=N'@RCOUT int output, @O_iErrorStateOUT int output, @oErrStringOUT nvarchar(255) output'print 'This is the CODE: ' + @SQL + '...This is the Parm: ' + @ParmDefEXECUTE sp_executesql @SQL, @ParmDef, @RCOUT=@RC OUTPUT, @O_iErrorStateOUT=@O_iErrorState, @oErrStringOUT= @oErrStringif @RC<> 0 breakfetch batchcur into @I_vVendorID, @I_vDocamnt, @I_vTRXDSCRN end close batchcur deallocate batchcur |
|