I am new to SQL Server, and am having trouble joining several SELECT statements together.
I have three SQL Select statements that do separate count operations to get the status of many projects. (One statement counts the number of open projects, one counts the number of completed projects, and the third one counts the number of late projects.) The count operations use GROUP BY project to operate.
An example of one of these queries is:
Expand|Select|Wrap|Line Numbers
- -- open
- SELECT PROJECT, COUNT(*) AS OPENAI
- FROM dbo.ACTION_ITEM sel_open
- WHERE (ACTUAL_DATE IS NULL) AND (DUE_DATE >= GETDATE())
- GROUP BY PROJECT
Expand|Select|Wrap|Line Numbers
- -- complete
- SELECT PROJECT, COUNT(*) AS COMPLETEAI
- FROM dbo.ACTION_ITEM sel_comp
- WHERE (ACTUAL_DATE IS NOT NULL)
- GROUP BY PROJECT
I would like to create a query that joins these three select statements together so my result has the form
PROJECT | OPEN | CLOSED | LATE
projectA | 3 | 1 | 2
projectB | 4 | 6 | 3
etc.
I have tried:
Expand|Select|Wrap|Line Numbers
- SELECT PROJECT, OPENAI
- FROM sel_comp LEFT JOIN sel_open
- ON sel_comp.PROJECT= sel_open.EFFECTIVITY
"Invalid object name 'sel_all' " and is unhappy with the FROM statement.
Can anyone tell me what I'm doing wrong?
Thanks
nickvans