Hello I'm tying to create query that selects data from two tables depending on the Employee and the range of dates. I have not used outer joins before and I either receive no data or receive too much data.
SELECT qad.NEW_USERS, qad.TRANSACTIONS, CONVERT( VARCHAR, qad.DATA_DATE, 101) DATA_DATE,
qas.QA_SCORE
FROM QA_SCORES qas FULL OUTER JOIN QA_DATA qad
ON (qas.EMPLOYEE_ID = qad.EMPLOYEE_ID AND qas.QA_DATE >= @startDate AND qas.QA_DATE < @endDate)
WHERE qad.DATA_DATE >= @startDate AND qad.DATA_DATE < @endDate
ORDER BY qad.DATA_DATE
Here are the tables:
QA_DATA:
| QA_DATA_ID | EMPLOYEE_ID | NEW_USERS | TRANSACTIONS | DATA_DATE |
| 4 | 11 | 0 | 0 | 12/1/2006 |
| 5 | 11 | 9 | 14 | 12/2/2006 |
| 6 | 1 | 2 | 3 | 1/1/2006 |
| 7 | 1 | 2 | 3 | 12/1/2006 |
| 8 | 11 | 6 | 18 | 12/3/2006 |
| 9 | 11 | 14 | 17 | 12/4/2006 |
| 10 | 11 | 7 | 16 | 12/5/2006 |
| 11 | 12 | 8 | 15 | 12/1/2006 |
| 12 | 12 | 0 | 0 | 12/3/2006 |
| 13 | 12 | 8 | 21 | 12/4/2006 |
QA_SCORES:
| QA_ID | QA_DATE | QA_SCORE | EMPLOYEE_ID |
| 1 | 1/18/2007 | 85 | 11 |
| 2 | 1/9/2007 | 83.01 | 11 |
Sometimes I receive this:
NEW_USERS
TRANSACTIONS
DATA_DATE
QASCORE
0
0
12/1/2006
85
0
0
12/1/2006
83.01
9
14
12/2/2006
83.01
9
14
12/2/2006
85
6
18
12/3/2006
85
6
18
12/3/2006
83.01
14
17
12/4/2006
83.01
14
17
12/4/2006
85
7
16
12/5/2006
85
7
16
12/5/2006
83.01
If the startDate = 12/01/2006 and the endDate = 12/31/2006 it should look like this:
| NEW_USERS | TRANSACTIONS | DATA_DATE | QASCORE |
| 0 | 0 | 12/1/2006 | |
| 9 | 14 | 12/2/2006 | |
| 6 | 18 | 12/3/2006 | |
| 14 | 17 | 12/4/2006 | |
| 7 | 16 | 12/5/2006 |
Because there are no QA_SCOREs in 2006
And if the start date is 1/01/2007 and the endDate is 1/31/2007 it should look like this:
| NEW_USERS | TRANSACTIONS | DATA_DATE | QASCORE |
| 1/9/2007 | 85 | ||
| 1/18/2007 | 83.01 |
I have tried quite a few things and just can't figure this out.
Any help is appreciated.
.