Include a row for missing records

treva26

Registered User.
Local time
Today, 07:36
Joined
Sep 19, 2007
Messages
113
I have a report that uses this query which lists the ACTIONS for each ELEMENT of each PROJECT.
This works fine.

I have attached an image of the query layout and its SQL is below.


How can I get it to also include a row for any ELEMENTs or PROJECTS that dont have any ACTIONS associated with it?
I want this in the report so that it is clear that they need to create some actions.

Code:
SELECT dbo_PR_Actions.PR_Action_ID, dbo_PR_Actions.Action_Date, dbo_PR_Actions.Action_DueDate, dbo_PR_Actions.Action_Completed, dbo_PR_Actions.Action, dbo_PR_Actions.Action_Status, dbo_PR_ElementTable.Element_Num, dbo_PR_ElementTable.Element_Name, dbo_PR_ProjectTable.Project_Num, dbo_PR_ProjectTable.Project_Name, dbo_PR_ProjectTable.Sales_Rep, dbo_PR_ProjectTable.Project_Status
FROM (dbo_PR_Actions LEFT JOIN dbo_PR_ElementTable ON dbo_PR_Actions.Element_Num = dbo_PR_ElementTable.Element_Num) LEFT JOIN dbo_PR_ProjectTable ON dbo_PR_ElementTable.Project_Num = dbo_PR_ProjectTable.Project_Num
WHERE (((dbo_PR_ProjectTable.Project_Status)<>"Lost" And (dbo_PR_ProjectTable.Project_Status)<>"Completed"));
 

Attachments

  • QueryDesign1.jpg
    QueryDesign1.jpg
    30.9 KB · Views: 80
Well I realised all I needed to do was change the Left Joins to Right Joins..
Doh

Code:
SELECT dbo_PR_Actions.PR_Action_ID, dbo_PR_Actions.Action_Date, dbo_PR_Actions.Action_DueDate, dbo_PR_Actions.Action_Completed, dbo_PR_Actions.Action, dbo_PR_Actions.Action_Status, dbo_PR_ElementTable.Element_Num, dbo_PR_ElementTable.Element_Name, dbo_PR_ProjectTable.Project_Num, dbo_PR_ProjectTable.Project_Name, dbo_PR_ProjectTable.Sales_Rep, dbo_PR_ProjectTable.Project_Status
FROM (dbo_PR_Actions RIGHT JOIN dbo_PR_ElementTable ON dbo_PR_Actions.Element_Num = dbo_PR_ElementTable.Element_Num) RIGHT JOIN dbo_PR_ProjectTable ON dbo_PR_ElementTable.Project_Num = dbo_PR_ProjectTable.Project_Num
WHERE (((dbo_PR_ProjectTable.Project_Status)<>"Lost" And (dbo_PR_ProjectTable.Project_Status)<>"Completed"));
 

Users who are viewing this thread

Back
Top Bottom