You could create a days calendar and join your tables to it
CREATE FUNCTION [dbo].[DAY_CALENDAR]
(
@StartDate TDATETIME,
@EndDate TDATETIME
)
RETURNS
@DYCALENDAR TABLE
(
StartDate DATETIME,
EndDate DATETIME,
OnDay DATETIME
)
AS
BEGIN
DECLARE @varStartTime TDATETIME, @varEndTime TDATETIME
set @varStartTime = DATEADD(dd, 0, DATEDIFF(dd, 0, @StartDate))
while @varStartTime <= @EndDate
begin
set @varEndTime = DATEADD(DD, 1, @varStartTime) --end time
set @varRes = @varStartTime
insert into @DYCALENDAR
values (@varStartTime, @varEndTime, @varStartTime)
set @varStartTime = @varEndTime
end
RETURN
END
Query
SELECT *
FROM CodeLogging log
INNER JOIN CodeReference ref ON log.code = ref.code
INNER JOIN DAY_CALENDAR(08/01/2010', '08/31/2010') LOGDAYS ON
(log.date >= LOGDAYS.StartDate and log.Date < LOGDAYS.EndDate)