Link to home
Start Free TrialLog in
Avatar of HSI_guelph
HSI_guelphFlag for Canada

asked on

Query not returning second row for almost identical time entry

I have a report that displays the hours submitted by employees for the selected team during a given time period and breaks the hours down by service codes so I can group and total by billable and non-billable.  We noticed that the numbers were not adding up and what seemed to happen is that the employee entered two half-hour entries under the same code for the same day but the query only returned one of the rows.  I am not restricting the code by a DISTINCT so I don't understand why it would ignore the second row.  I included the PK ID and the missing entry showed up.  The code is a mess pulling from multiple tables but even if there are two or more rows with the identical entries it should not omit one unless I specified it to be unique or DISTINCT (?).  Adding the PK has resolve the issue but now I worry that other reports might also be affected if SSRS is just omitting rows.  I can't see anything in the code that would specify this behavior so I am assuming it is something with SSRS, a odd behavior I don't understand and have to do a workaround to avoid it.

Any insight into why this has happened so I can eliminate the potential for future errors would be greatly appreciated!!

SELECT     EmpCustom.EmpCustValue AS Team, Employee.Emplevel AS Level, Employee.Empfname + ' ' + WIP.WEmpLName AS Employee, WIP.WCltName AS Project, 
                      WIP.WCodeCat AS ServiceCategory, WIP.WCodeSub AS SubCategory, WIP.WCodeSer AS Service, ISNULL(WIP.Whours, 0) AS Hours, ISNULL(WIP.Wfee, 0) AS Amount,
                       ISNULL(WIP.Wdate, 0) AS Date, Department.DeptName AS TeamDept, EmpCustom.EmpCustValue AS TeamColour, WIP.ID
FROM         WIP RIGHT OUTER JOIN
                      Employee ON WIP.WempID = Employee.ID INNER JOIN
                      Department ON Employee.Empdept = Department.DeptID INNER JOIN
                      EmpCustom ON Employee.ID = EmpCustom.EmpCustEmpId
WHERE     (WIP.Wdate >= @StartDate) AND (Employee.ID > 1) AND (EmpCustom.EmpCustValue = @TeamColour) AND (WIP.Windicator <> 'D') AND (WIP.Wdate <= @StartDate + 6)
GROUP BY EmpCustom.EmpCustValue, Employee.Emplevel, Employee.Empfname, WIP.WEmpLName, WIP.WCltName, ISNULL(WIP.Wdate, 0), WIP.Whours, ISNULL(WIP.Wfee,
                       0), Department.DeptName, WIP.WCodeCat, WIP.WCodeSer, WIP.WCodeSub, WIP.ID
ORDER BY TeamColour, Level, Employee, ServiceCategory, Date DESC

Open in new window


User generated image
SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HSI_guelph

ASKER

I haven't stripped the time off, time of day is the same for every entry, would this affect the duplicate row (when no id is included) not showing up?  I actually had a BETWEEN there but changed it up today because I remember an article on EE that spoke about how it was better to avoid using BETWEENs.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The Employee.ID > 1 is because expenses are entered under Employee ID 1 (admin).  
I think at some point I was grouping the hours but I don't see a sum so I must have changed that.  When I removed the Group By I now get 38 results instead of 37.  

Thank you both for the assist in cleaning up my code.
Removing the Group By returned the correct number of results.