× 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.



I would suggest using joins instead of MSQuery syntax.

select b.bintype, count(b.bintype)
from tablea a
join tableb b
on a.partno = b.partno
and a.plantcode = b.plantcode -- I'm assuming that this should be part of your key to join the two tables. If not then remove
join tablec c
on a.partno = c.partno
and a.plantcode = c.plantcode -- I'm assuming that this should be part of your key to join the two tables. If not then remove
where a.plantcode = '1' and c.shiptype = 'PS'
and digits(dec(a.scyy,4,0))||digits(dec(a.scmm,2,0))||digits(dec(a.scdd,2,0)) = '20110209'
group by b.bintype


Use functions digits and dec to recast the year, month and day fields so that you can keep the number of characters used in the fields so that if you want to do a date range, you could.


-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Brian Piotrowski
Sent: Tuesday, February 22, 2011 2:06 PM
To: Midrange Systems Technical Discussion
Subject: Complex Query Help

Hi All,

I'm trying to consolidate three tables into a single result and I'm wondering if someone can give me a few ideas....

I have these tables:

TABLE A
Plant Code
Part Number
Part Colour
Scan Date (in three integer fields: YY, MM, DD (don't ask - the legacy programmers did not know how to use timestamps!))

TABLE B
Plant Code
Part Number
Bin Type

Table C
Plant Code
Part Number
Ship Type

What I want to do is combine the values into a result that has these fields for 02/09/2011:
Bin Type
Quantity for each bin type

Quantity is a sum of each bin type for the selected plant/part #.
IE:
Plant 1, Part: 12345, Bin Type: X1
Plant 1, Part: 67711, Bin Type: X2
Plant 2, Part: 67711, Bin Type: X2
Plant 3, Part: 90009, Bin Type: X3
Plant 2, Part: 90191, Bin Type: X1
Plant 1, Part: 12345, Bin Type: X1

If the above was entered into the system, I would expect the report to be:
Plant Code | Part Number | Bin Type | Quantity
1 | 12345 | X1 | 2
1 | 67711 | X2 | 1
2 | 67711 | X2 | 1
3 | 90009 | X3 | 1
2 | 90191 | X1 | 1

However, this is not the case - I am getting an insane amount of records when I try this (I know it is incorrect because one of the bins says we brought in over three million of them in a single day!!):

select b.bintype, count(b.bintype)
from tablea a, tableb b, tablec c
where a.partno = b.partno and a.partno = c.partno
and a.plantcode = '1' and c.shiptype = 'PS'
and a.scyy||a.scmm||a.scdd = '201129'
group by b.bintype

Anyone have any idea how I can rewrite this statement so that it gives me the correct values?

Thanks!

/b;


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Brian Piotrowski
Assistant Mgr. - I.T.
Simcoe Parts Service, Inc.
Ph: 705-435-7814 x343
Fx: 705-435-5029
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
http://www.simcoeparts.com

Please consider the environment. Don't print this e-mail unless you really need to.

The information contained in this communication is confidential and intended only for the use of those to whom it is addressed. If you have received this communication in error, please notify me by telephone (collect if necessary) and delete or destroy any copies of it. Thank you!

--
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.

________________________________

Notice from Bob Evans Farms, Inc: This e-mail message, including any attachments, may contain confidential information that is intended only for the person or entity to which it is addressed. Any unauthorized review, use, disclosure or distribution is strictly prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message and any attachments.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.