Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL / GROUP BY (Join)
Message
 
To
26/09/2003 12:48:44
John Vlahos
V I Software Solutions Design
Mississauga, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00832747
Message ID:
00832754
Views:
14
Try switching the two tables:
SELECT LINE.cCode, SUM(ROLLS.nWeight_Roll) AS nAccepted ;
FROM ROLLS ;
LEFT OUTER JOIN LINE ;
ON LINE.ID=ROLLS.clineid ;
WHERE UPPER(ALLTRIM(CSTATUS))=="ACCEPTED" ;
GROUP BY LINE.cCode ;
Another cause may be the WHERE clause? What table is CSTATUS coming from? If it's the LINE table, which the record doesn't exist for all records in ROLLS, this would eliminate that record in ROLLS. Change the WHERE to:
WHERE ISNULL(LINE.CSTATUS) OR UPPER(ALLTRIM(CSTATUS))=="ACCEPTED"
>I am uing the following SQL statement:
>
>SELECT LINE.cCode, SUM(ROLLS.nWeight_Roll) AS nAccepted ;
>FROM LINE ;
>LEFT JOIN ROLLS ;
>ON LINE.ID=ROLLS.clineid ;
>WHERE UPPER(ALLTRIM(CSTATUS))=="ACCEPTED" ;
>GROUP BY LINE.cCode ;
>INTO CURSOR tmpProduction
>
>In my LINE table, I have 11 records. cCode={101,102,103....,111}.
>ROLLS table is the rolls produced on a particulare line/machine-line.
>
>I would like to have 11 records after my SQL statement executes in the temporary cursor, however I only get 5. This is because 6 of the lines have no ROLL records associated with them since no production was ever performed on those lines yet.
>
>How can I request that all lines are given, even if the SUM returns 0.00?
>
>Thanks in advance,
Cathy Pountney, Microsoft Visual FoxPro MVP
Memorial Business Systems, Inc. (www.mbs-intl.com)

My Website: (www.frontier2000.com)
My Blog: (www.cathypountney.blogspot.com)
My Book: The Visual FoxPro Report Writer - Pushing it to the Limit and Beyond
Free MSDN Article: What's New in the VFP 9.0 Report Writer
Free MSDN Article: The VFP 9.0 Report Writer In Action
Previous
Reply
Map
View

Click here to load this message in the networking platform