|
Atrix,
How
about if you write a stored procedure say GetTransTypeTotal that will accept two
arguments, AcctID and TranState?
The
stored procedure will return the result of this SELECT
statement.
SELECT (SUM(AcctIDAmount))
FROM TranAcctID
WHERE AcctID = <passed AcctID>
AND TranState = <passed
TranState>
With
this stored procedure you can use this select:
SELECT
AccountNo,AcctID,OrigApp,
(CALL
GetTransTypeTotal(AcctID,'A')) AS tmpA,
(CALL
GetTransTypeTotal(AcctID,'B')) AS tmpB,
(CALL
GetTransTypeTotal(AcctID,'C')) AS tmpC,
(CALL
GetTransTypeTotal(AcctID,'D')) AS tmpD,
(OrigApp - (CALL
GetTransTypeTotal(AcctID,'A')) - (CALL GetTransTypeTotal(AcctID,'B')) + (CALL
GetTransTypeTotal(AcctID,'D'))) AS
tmpBalance
FROM
Accounts
WHERE <whatever clause
you want>
I've used multiple CALLs on
SELECT statements and the performance is quite responsive. You have to
make sure you have good indexes on AcctID and
TranState.
This way also, if you add
new TranStates, all you have to do is change the 2nd argument in the stored
procedure call.
The only caveat though is
that the SELECT statements tend to get really long really quick.
:)
Good
luck,
Rommel
"There is always more than
one way to skin a cat."
PS: Yes, I always alias
"_expression_ columns" so the headers of the resultset will be more
helpful. :)
|
- [RBASE-L] - SQL longshot! Atrix Wolfe
- [RBASE-L] - RE: SQL longshot! Rommel Relosa
- [RBASE-L] - RE: SQL longshot! Atrix Wolfe

