The following batch aggregates records in one (INVSwitchTransValidTbl)and inserts the aggregates in table INVJobsTbl. It then gets the GUID created for the Jobs records and updates the records in INVSwitchTransValidTbl which formed the aggregates.
The script takes about 30 seconds to process 200,000 records in the INVSwitchTransValidTbl table. However when I put both statement in a single transaction it takes 11 minutes! Why does this cause such a significant difference?
Any help appreciated.
Yael
The script takes about 30 seconds to process 200,000 records in the INVSwitchTransValidTbl table. However when I put both statement in a single transaction it takes 11 minutes! Why does this cause such a significant difference?
Code:
--insert Aggregates for each Brd into Jobs table
INSERT INTO INVJobsTbl(JobID,nodeAccountcode, JobTypeID, PeriodID, Jobref, JobTime, JobCharge, Qty)
SELECT newid()JobID ,NodeAccountCode, 2, 1 , mid, RecvTime, sum(retailCharge), count(*) FROM INVSwitchTransValidTbl
WHERE TypeInd_Brd = 2 AND Aggregated = 0
Group by NodeAccountCode, mid, RecvTime
--Update BRD trans recs with the new JobID
UPDATE t SET JobID = j.jobID
FROM INVJobsTbl j JOIN INVSwitchTransValidTbl t
ON j.jobRef = t.MID AND j.jobtime = t.RecvTime
WHERE TypeInd_Brd = 2 AND Aggregated = 0
Any help appreciated.
Yael