I think I should get the Stupidity award <g>. In my SQL select there is a WHERE clause (which of course I didn't pay attention to <g>) that specifies the range of Receiving dates.
Therefore, the SQL select should be as follows:
select PARTS.PART_NO, sum( PARTS_RECEIVED.QTY ) as SUM_QTY from PARTS ;
left join PO_PARTS on PARTS.PART_NO = PO_PARTS.PART_NO ;
left join PARTS_RECEIVED on PO_PARTS.POPART_PK = PARTS_RECEIVED.POPART_PK ;
where PARTS_RECEIVED.DATE_REC between ("this date" and "that date")
Now that I know why it does not work, I still need help. Is it possibel to STILL have in the resulting query all records from PARTS? That is, I want the SUM_QTY for those parts which are not within Receiving Date Range to be set to 0.00 yet still included in the query.
Is it possible?
>No, I don't see anything wrong. What VFP version are you using, 6? Can you zip up small subset of your data and email to me so I can run some tests?
>
>>Sergey,
>>I do have the GROUP BY in my code, I just missed it here in UT message.
>>Do you see anything else that might be wrong with my code?
>>
>>>Hi Dmitry,
>>>
>>>Your select is missing
GROUP BY PARTS.PART_NO
>>>
>>>>I am having another problem, which probably stems from my misunderstanding of SQL Select.
>>>>
>>>>Three tables:
>>>>
>>>>Table 1: PARTS
>>>>Fields: PART_NO, etc.
>>>>
>>>>Table 2: PO_PARTS (purchased parts)
>>>>Fields: PART_NO, POPART_PK, etc.
>>>>
>>>>Table 3: PARTS_RECEIVED
>>>>Fields: POPART_PK, DATE_REC, QTY, etc.
>>>>
>>>>When I have the following query:
>>>>
>>>>
>>>>select PARTS.PART_NO, sum( PARTS_RECEIVED.QTY ) as SUM_QTY from PARTS ;
>>>>left join PO_PARTS on PARTS.PART_NO = PO_PARTS.PART_NO ;
>>>>left join PARTS_RECEIVED on PO_PARTS.POPART_PK = PARTS_RECEIVED.POPART_PK
>>>>
>>>>
>>>>I get only those records from PARTS that have entries in PO_PARTS. I thought this SQL Select (because it is left join) would have all records from PARTS table.
>>>>
>>>>What am I missing?
>>>>
>>>>TIA.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham