× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Where does ordnum come from - Craig, you don't show that field in your sample data. But assuming it is in a related file, this solution below looks kind of complicated and could be handled with a simple group by, as here:

select ordnum, sum(qty)
from ordfile join transact file on ordfile.type = transact.type
group by ordnum, type

With this you don't need to hard code the type codes - it just gets done. This gets you separate totals for each type code - which, I believe, the first suggestion does, too. If you want just the totals over all type codes, use this:

select ordnum, sum(qty)
from ordfile join transact file on ordfile.type = transact.type
group by ordnum

HTH
Vern

At 07:24 AM 5/29/2007, you wrote:

Craig Jacobsen wrote on 29/05/2007 08:14:46:

> I am trying to get totals of a transaction file that has multiple record
> types. I know I saw something on this recently, but I can't seem to
find
> it. I have a file that has various types with quantities for each type.
I
> would like to add up each type (record looks like--type PA qty 24, type
PI
> qty 12) based on Order/Line# in one SQL statement. There are multiple
> records per type and 4 different types.

Would something like this do the trick?

SELECT ordnum,
SUM (CASE WHEN type = 'PA' THEN qty ELSE 0 END),
SUM (CASE WHEN type = 'PI' THEN qty ELSE 0 END),
SUM (CASE WHEN type = <type3> THEN qty ELSE 0 END),
SUM (CASE WHEN type = <type4> THEN qty ELSE 0 END)
FROM ...

where <typeX> is replaced by the code for the appropriate type.

HTH,
Adam

Attention:

The information contained in this message and or attachments is
intended only for the person or entity to which it is addressed and may contain
confidential and/or privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance upon, this
information by persons or entities other than the intended recipient is
prohibited. If you received this message in error, please contact the sender and
delete the material from any system and destroy any copies. Thank you for your
time and consideration.

Attention:

Le contenu de ce message et(ou) les fichiers ci-joints s?adressent
exclusivement à la personne ou -entité à laquelle ils sont destinés. Ils peuvent
contenir de l?information confidentielle, protégée et(ou) classifiée. Il est
strictement interdit à toute personne ou entité autre que le(la) destinataire
prévu(e) de ce message d?examiner, de réviser, de retransmettre ou de diffuser
cette information, de prendre une quelconque action en fonction ou sur la base
de celle-ci, ou d?en faire tout autre usage. Si vous avez reçu ce message par
erreur, veuillez communiquer avec l?expéditeur(trice), supprimer ce message et
les fichiers ci-inclus de tout système, et en détruire toutes copies, qu?elles
soient électroniques ou imprimées. Nous vous remercions de votre entière
collaboration.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.