Advertisement

05.21.2008 at 06:48AM PDT, ID: 23420773
[x]
Attachment Details

Query or Stored procedure to return hours all days in month for all employees - even if none were recorded for the employee

Asked by Angela_Wilcox in MS SQL Server, Databases Miscellaneous, SQL Query Syntax

Tags: Microsoft, SQL Server, 2000, Query or Stored Procedure

I need to create a query or a stored procedure that will return all the time entry records for all employees - even if the employee didn't record time for the given day.  

Time_Table
* EmployeeID
* ProjectID
* TimeEntryDate
* TimeEntryHours

I created a table called Date_Table that contains the date (DT_Date) for every day in the year.  

I tried creating a view with the query like this:

SELECT EmployeeID, ProjectID, DT_Date, SUM(TimeEntryHours)
FROM Date_Table
LEFT OUTER JOIN Time_Table
ON DT_Date = TimeEntryDate
GROUP BY EmployeeID, ProjectID, DT_Date

I end up getting a bunch of null records back - so it isn't giving me the missing dates for each employee with a zero (0) for the hours.  The project ID for the missing dates can be null.

I'm guessing I need to use a stored procedure rather than the query and loop thru each employee and create the record in a temp table for the missing dates.  Would I still use the date table I created or is there a better way to loop thru the months and create the missing records for each day for each employee?  Can anyone get me started on that?    Thank You!Start Free Trial
 
 
Loading Advertisement...
 
[+][-]05.21.2008 at 06:59AM PDT, ID: 21615091

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 07:05AM PDT, ID: 21615141

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 07:07AM PDT, ID: 21615166

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 07:12AM PDT, ID: 21615203

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 08:08AM PDT, ID: 21615867

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, Databases Miscellaneous, SQL Query Syntax
Tags: Microsoft, SQL Server, 2000, Query or Stored Procedure
Sign Up Now!
Solution Provided By: ScottPletcher
Participating Experts: 4
Solution Grade: A
 
 
[+][-]05.22.2008 at 11:26PM PDT, ID: 21629774

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 07:35AM PDT, ID: 21632491

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628