I've got an app with a Supply table and a Detail table. Detail table/screen has 6 different "Item" and "Quantity" fields, so you can order up to 6 items. Each item field can select any item from the Supply table.
Supply.idno -> Detail.item1
...
Supply.idno -> Detail.item6
So from any Detail record, the Supply item "AAAAA" could show up in Detail.item1, Detail.item2, ..., Detail.item6.
I'm trying to run either a query or Crystal report that will group by Supply.idno and give me a sum of quantity of each item no matter which field it shows up in.
I came up with the following query to get the sum for just one Detail field, but can't figure out how to aggregate them all. I would rather not have to run this query 6 times and manually add up all the quantities:
select s.idno, sum(d.qty_1) from supply s, detail d where s.idno = d.itemcode_1 group by s.idno;
Supply.idno -> Detail.item1
...
Supply.idno -> Detail.item6
So from any Detail record, the Supply item "AAAAA" could show up in Detail.item1, Detail.item2, ..., Detail.item6.
I'm trying to run either a query or Crystal report that will group by Supply.idno and give me a sum of quantity of each item no matter which field it shows up in.
I came up with the following query to get the sum for just one Detail field, but can't figure out how to aggregate them all. I would rather not have to run this query 6 times and manually add up all the quantities:
select s.idno, sum(d.qty_1) from supply s, detail d where s.idno = d.itemcode_1 group by s.idno;