Write a SQL Query to replace values and include all the Dates.
Posted
by VJ
on Stack Overflow
See other posts from Stack Overflow
or by VJ
Published on 2010-05-19T16:55:27Z
Indexed on
2010/05/19
17:10 UTC
Read the original article
Hit count: 164
Well I have this -
Table DimDate- Date
Table Employee- Id,Name,Points,Date
Now the Employee table has points for everyday unless they did not come...so the Date does not have all the Dates entries... I mean for e.g in a week he did not come for 2 days the Employee table has only 5 rows...so I have this dimdate table which has all the dates till 2050 which I want to join with and add Zeros for the dates he does not have points. So I have written this query but does not work -
Select E.EmployeeId,D.Date,isNull(E.Points,0)
from DimDate D left join Employee E on D.Date between
'01-01-2009'and '06-01-2009' where E.EmployeeId=1
The above query give multiple dates and I tried group by on Date but does not work.
© Stack Overflow or respective owner