Re: conditional select sum() based on field question
Posted in 1992
In article <9305@emory.mathcs.emory.edu> A.Heskett@bnr.co.uk (Tony Heskett) writes: > > Pete Frehner writes: > > > [ ... add or subtract according to record type, only scan table once ... ] > > Call me stupid (go on, I'm waiting :-) but why don't you just > do this ? Is a cursor *much* slower ? > [fetch-loop to scan table adding and subtracting amounts, omitted] You ain't stupid (at least on present evidence :-) but a cursor ought to be slower for this problem. Reason: your cursor scan requires passing every row from the engine to the program. Each trip back and forth between engine and application costs time. Any solution that has the engine calculate the sum should be faster because less stuff is shoved through the pipes.