Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vision.v1
Yak Posting Veteran
72 Posts |
Posted - 2010-06-15 : 11:45:44
|
| Hi, I have two tables Employee and Hours Employee Table---------------Employeeid FirstName111 StevenHoursTable----------Employeeid weekNo glAccount weekEndDate weekHours111 22 NULL 05/29/2010 88111 22 145 05/29/2010 24.3111 23 145 06/06/2010 44Now i want to show the result set of the two table in single row likeEmployeeid glAccount weekEnd1Date week1Hours weekEnd2Date week2Hours111 NULL 05/29/2010 88 06/06/2010 0111 145 05/29/2010 24.3 06/06/2010 44please tell me how to join both the tables to get the result as shown aboveI tried like below:SELECT a.employeeId, '05/29/2010' [Week 1 End Date], SUM(b.weekHours) week1Reg, '06/06/2010' [Week 2 End Date], SUM(c.weekHours) week2RegFROM Employee aLEFT JOIN HoursTable bON a.employeeid = b.employeeid AND b.weekNo = 22LEFT JOIN HoursTable cON a.employeeId = c.employeeid AND c.weekNo = 23GROUP BY a.employeeidbut the result is showing wrong valuesplease suggestThanks |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-15 : 13:36:59
|
Your expected result doesn't make sense to me. On what basis are you splitting the records like how you are doing.What is there is no more row like this?111 22 NULL 05/29/2010 99 Can you provide a bigger sample of your data and show expected results. |
 |
|
|
|
|
|