home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!caen!sol.ctr.columbia.edu!emory!bnr.co.uk
- From: A.Heskett@bnr.co.uk (Tony Heskett)
- Newsgroups: comp.databases.informix
- Subject: Re: conditional select sum() based on field question
- Message-ID: <9305@emory.mathcs.emory.edu>
- Date: 13 Aug 92 19:48:08 GMT
- Sender: walt@mathcs.emory.edu
- Reply-To: A.Heskett@bnr.co.uk (Tony Heskett)
- Lines: 49
- X-Informix-List-ID: <list.1377>
-
-
- Pete Frehner writes:
-
- > [ ... add or subtract according to record type, only scan table once ... ]
-
- > select sum(amount) into total_credits
- > from orders where order_type = "CREDIT"
- >
- > select sum(amount) into total_normal_orders
- > from orders where order_type = "REG"
- >
- > let net_amount = total_normal_orders - total_credits
-
- Call me stupid (go on, I'm waiting :-) but why don't you just
- do this ? Is a cursor *much* slower ?
-
- declare a_curs cursor for
- select amount, order_type
- from orders
- where order_type = "CREDIT"
- or order_type = "REG"
-
- fetch a_curs into amt, ord
-
- while status = 0
-
- if ord = "CREDIT"
- net_amount = net_amount + amt
- else
- net_amount = net_amount - amt
-
- fetch a_curs into amt, ord
-
- end while
-
- close a_curs
-
- Incidentally, does anyone else miss not having += -= and friends ?
- COBOL-fingers, here we come ...
-
- > Pete Frehner Voice (519) 673-3350
- > Praeda Management Systems Fax (519) 667-1968
- > 371 Dufferin Ave. uucp: .....uunet!praeda!pfrehner
- > London, Ontario CANADA N6B 1Z5
-
- Cheers - Tony.
- _________________________________________________________________________
- Tony Heskett th@bnr.co.uk Phone: (+44) 279 402637
- BNR, London Road, Harlow, Essex CM17 9NA Fax: (+44) 279 451434
-