This isn't set to work against all modules, but if you look and see what's going on, it can be easily adopted.
-- =============================================
-- Steve Gray
-- 4Penny.net
-- 941-747-3669
-- =============================================
IF EXISTS (SELECT name
FROM sysobjects
WHERE name = N'_4P_sy00500_UPD'
AND type = 'P')
DROP PROCEDURE _4P_sy00500_UPD
GO
CREATE PROCEDURE _4P_sy00500_UPD
-- _4P_sy00500_UPD 'import','RM_Sales', 'sgray',3
@vchrBatchNumber varchar(15),
@bchsourc varchar(15),
@vchrUserID varchar(15) ,
@intSeries int = 3
AS
declare @currDocAmount as money
declare @intDocCount as int
declare @dtDate as datetime
set @dtDate = convert(varchar(10), getdate(),101)
--============================================================================
-- create the batch, if necessary
--============================================================================
--see if the batch exists
if not exists (select dex_row_id
from sy00500 with (nolock)
where bachnumb = @vchrBatchNumber
and bchsourc = @bchsourc)
insert into sy00500 (GLPOSTDT, BCHSOURC ,BACHNUMB , SERIES , MKDTOPST, NUMOFTRX, RECPSTGS, DELBACH, MSCBDINC, BACHFREQ, RCLPSTDT , NOFPSTGS, BCHCOMNT, BRKDNALL, CHKSPRTD, RVRSBACH, USERID , CHEKBKID , BCHTOTAL, BCHEMSG1, BCHEMSG2, BACHDATE , BCHSTRG1, BCHSTRG2, POSTTOGL, MODIFDT, CREATDDT, NOTEINDX, CURNCYID, BCHSTTUS, CNTRLTRX, CNTRLTOT, PETRXCNT, APPROVL, APPRVLDT, APRVLUSERID, ORIGIN, ERRSTATE, GLBCHVAL, Computer_Check_Doc_Date, Sort_Checks_By, SEPRMTNC, REPRNTED, CHKFRMTS, TRXSORCE, PmtMethod, EFTFileFormat)
values (@dtDate , @bchsourc ,@vchrBatchNumber, @intSeries, 0 , 0 , 0 , 0 , 0 , 1 , '1/1/1900', 0 , '' , 0 , 0 , 0 , @vchrUserID, 'ST OPERATING', 0.00 , 0 , 0 , '1/1/1900', '' , '' , 0 , @dtDate, @dtDate , 0 , 0 , 0 , 0 , 0 , 0 , 0 , @dtDate , '' , 1 , 0 , 0 , '1/1/1900' , 0 , 0 , 0 , 0 , '' , 0 , 1)
set @intDocCount = 0
set @currDocAmount = 0
if @bchsourc = 'Sales Entry' begin
--get the number of docs and the sum
select
@intDocCount = count(docamnt),
@currDocAmount = isnull(sum(docamnt),0)
from sop10100 with (nolock)
where bachnumb = @vchrBatchNumber
and voidstts = 0
end
if @bchsourc = 'RM_Sales' begin
--get the number of docs and the sum
select
@intDocCount = count(docamnt),
@currDocAmount = isnull(sum(dbo.f_4p_Modifier2(docamnt, rmdtypal)),0)
from rm10301 with (nolock)
where bachnumb = @vchrBatchNumber
end
if @bchsourc = 'IV_Trxent'
select
@intDocCount = count(trxqtytl),
@currDocAmount = sum(trxqtytl)
from iv10000 with (nolock)
where bachnumb = @vchrBatchNumber
if @bchsourc = 'PM_Trxent'
select
@intDocCount = count(DOCAMNT),
@currDocAmount = sum(DOCAMNT)
from pm10000 with (nolock)
where bachnumb = @vchrBatchNumber
--update the batch with that info
if @currDocAmount = 0 begin
delete sy00500
where bachnumb = @vchrBatchNumber and bchsourc = @bchsourc
end else begin
update sy00500 set
numoftrx = @intDocCount,
nofpstgs = 0,
bchtotal = @currDocAmount
where bachnumb = @vchrBatchNumber and bchsourc = @bchsourc
end
GO
grant all on _4P_sy00500_UPD to public