Hello Experts,
Below is a SELECT statement I am using from within VBA (Excel 2003) to populate a spreadsheet from a Firebird SQL v1.5 DB. Spreadsheet population works well, BUT...
I have three tables: JOBS, INVOICE, and SHIPMASTER
All tables are linked by the field: JOBNO
Eight fields are being pulled in the order they are needed on the spreadsheet.
JOBS has only one record for each JOBNO
INVOICE and SHIPMASTER may have multiple records for each JOBNO
str_Select = _
"SELECT J.CUSTNAME, J.JOBNO, I.INVUNINO, J.CRETDATE, J.NEEDDATE, I.INVDATE, S.SHIPDATE, J.JOBSTATS FROM JOBS J " & _
"LEFT OUTER JOIN INVOICE I on J.JOBNO = I.JOBNO " & _
"INNER JOIN SHIPMASTER S on I.JOBNO = S.JOBNO " & _
"WHERE J.CRETDATE >= '01.01.2007' " & _
"ORDER BY CRETDATE" & ";"
In the results, I get: (No matter how I arrange the JOINS")
CUSTNAME JOBNO INVUNINO CRETDATE NEEDDATE INVDATE SHIPDATE JOBSTATS
J & C INDUSTRIES 10277 21641 1/4/2007 2/15/2007 1/26/2007 1/26/2007 CLOSED
J & C INDUSTRIES 10277 21662 1/4/2007 2/15/2007 1/30/2007 1/26/2007 CLOSED
J & C INDUSTRIES 10277 21737 1/4/2007 2/15/2007 2/15/2007 1/26/2007 CLOSED
J & C INDUSTRIES 10277 21641 1/4/2007 2/15/2007 1/26/2007 1/30/2007 CLOSED
J & C INDUSTRIES 10277 21662 1/4/2007 2/15/2007 1/30/2007 1/30/2007 CLOSED
J & C INDUSTRIES 10277 21737 1/4/2007 2/15/2007 2/15/2007 1/30/2007 CLOSED
J & C INDUSTRIES 10277 21641 1/4/2007 2/15/2007 1/26/2007 2/15/2007 CLOSED
J & C INDUSTRIES 10277 21662 1/4/2007 2/15/2007 1/30/2007 2/15/2007 CLOSED
J & C INDUSTRIES 10277 21737 1/4/2007 2/15/2007 2/15/2007 2/15/2007 CLOSED
THIS is what the results should look like: (There is One record in JOBS, Three records in INVOICE, and Three records in SHIPMASTER)
J & C INDUSTRIES 10277 21641 1/4/2007 2/15/2007 1/26/2007 1/27/2007 CLOSED
J & C INDUSTRIES 10277 21662 1/4/2007 2/15/2007 1/30/2007 1/30/2007 CLOSED
J & C INDUSTRIES 10277 21737 1/4/2007 2/15/2007 2/15/2007 2/15/2007 CLOSED
What is wrong with that SELECT statement? Should I be using a UNION, if so how would I implement that here?
TIA!