Avatar of Sim1980
Sim1980
 asked on

Not showing some records in SQL Select statement

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.
Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Sim1980

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ganapathi

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Sim1980

ASKER
Thanks! I have to do the same thing for our MySQL database, but I know FULL OUTER JOIN doesn't exist in MySQL so I'll post another question.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23