We help IT Professionals succeed at work.
Get Started

Not showing some records in SQL Select statement

Last Modified: 2014-05-09
Hi all.

I have the following SELECT statement:

SELECT Builder, Community, Charts,Concat(Users.firstname, ' ', Users.lastname) As Super, Concat(ProjectManagers.FirstName, ' ', ProjectManagers.LastName) As ProjectManager, Concat(Salesperson.FirstName, ' ', Salesperson.LastName) As Salesperson,
   SUM(CASE WHEN FieldSuperDataEntry.Type=1 THEN 1 ELSE 0 END) as Slabs, 
   SUM(CASE WHEN FieldSuperDataEntry.Type=2 THEN 1 ELSE 0 END) as DriedIn,
   COUNT(FieldSuperDataEntry.Type) as TotalCombined
FROM BuilderCommunity LEFT OUTER JOIN FieldSuperDataEntry  ON BuilderCommunity.BuilderCommunityID = FieldSuperDataEntry.BuilderCommunityID LEFT OUTER JOIN FieldSuperAssignment ON BuilderCommunity.BuilderCommunityID = FieldSuperAssignment.BuilderCommunityID LEFT OUTER JOIN Users ON FieldSuperAssignment.UserID = Users.userid LEFT OUTER JOIN ProjectManagerAssignment ON BuilderCommunity.BuilderCommunityID = ProjectManagerAssignment.BuilderCommunityID LEFT OUTER JOIN ProjectManagers ON ProjectManagerAssignment.ProjectManagerID = ProjectManagers.ProjectManagerID LEFT OUTER JOIN SalespersonAssignment ON BuilderCommunity.BuilderCommunityID = SalespersonAssignment.BuilderCommunityID LEFT OUTER JOIN Salesperson ON SalespersonAssignment.SalesPersonID = Salesperson.SalesPersonID LEFT OUTER JOIN JobType ON FieldSuperDataEntry.Type = JobType.jobtypeid WHERE FieldSuperDataEntry.CompletedFloorJob IS NULL AND FieldSuperDataEntry.Status IS NULL  AND BuilderCommunity.Status = 'Active'   
GROUP BY Builder, Community, Super, ProjectManager, SalesPerson
ORDER BY Builder, Community, Super, ProjectManager, Salesperson

Open in new window

It shows all of the counts for each community unless there is a community where ALL of it's data in the FieldSuperDataEntry table has either FieldSuperDataEntry.CompletedFloorJob = 'Completed' or FieldSuperDataEntry.Status = 'Completed', with these communities, they are NOT INCLUDED in the results. They should be included but with Slabs = 0, DriedIn = 0 and TotalCombined = 0.

Now, if a community does not have any data in the FieldSuperDataEntry table, then they are correctly appearing in the results with Slabs = 0, DriedIn = 0 and TotalCombined = 0.

How can I change my select statement to include ALL communities even those where all of it's data in the FieldSuperDataEntry table is already completed?

Thank you in advance.
Watch Question
Facets Developer
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE