• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Displaying Data that May Not Exist

I'm trying to create a stored procedure that Joins 2 tables - Employees and Hours
The problem is that an employee may not be active or may not have hours for a given week, and I need to represent that missing data with "0.0" but I cant get the query to return any rows for an employee if hours for a given week do not exist.


Select Employee.ID, LastName + FirstName as empName
    SUM(CASE WHEN wh.Regular  Is Not Null THEN wh.Regular  Else '0.0' END)
    SUM(CASE WHEN wh.OverTime Is Not Null THEN wh.OverTime Else '0.0' END)
 
From Employees LEFT OUTER JOIN EmployeeHours as wh on Employee.ID = wh.EmpID
 
Where WeekEnding = @WeekEnding
 
Group By Employee.ID, LastName, FirstName
Order By wh.Regular desc, wh.OverTime desc, empName asc
 
END

Open in new window

0
spudsoftware
Asked:
spudsoftware
1 Solution
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Try placing the condition in the join clause. I think that will do it for you.

Select Employee.ID, LastName + FirstName as empName
    SUM(CASE WHEN wh.Regular  Is Not Null THEN wh.Regular  Else '0.0' END)
    SUM(CASE WHEN wh.OverTime Is Not Null THEN wh.OverTime Else '0.0' END)
 
From Employees LEFT OUTER JOIN EmployeeHours as wh on Employee.ID = wh.EmpID
 AND WeekEnding = @WeekEnding
 
Group By Employee.ID, LastName, FirstName
Order By wh.Regular desc, wh.OverTime desc, empName asc
 
END
0
 
spudsoftwareAuthor Commented:
Yep, that did it!
Thanks a bunch
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now