Задача требует, чтобы полный набор дат был оставлен в ваших данных, например
<br/>DECLARE @StartInt int
<br/>DECLARE @Increment int
<br/>DECLARE @Iterations int
<br/>
<br/>SET @StartInt = 0
<br/>SET @Increment = 1
<br/>SET @Iterations = 365
<br/>
<br/>
<br/>SELECT
<br/> tCompleteDateSet.[Date]
<br/> ,AggregatedMeasure = SUM(ISNULL(t.Data, 0))
<br/>FROM
<br/> (<br>
<br/> SELECT
<br/> [Date] = dateadd(dd,GeneratedInt, @StartDate)
<br/> FROM
<br/> [dbo].[tvfUtilGenerateIntegerList] (
<br/> @StartInt,
<br/> ,@Increment,
<br/> ,@Iterations
<br/> )
<br/> ) tCompleteDateSet
<br/> LEFT JOIN tblData t
<br/> ON (t.[Date] = tCompleteDateSet.[Date])
<br/>GROUP BY
<br/> tCompleteDateSet.[Date]
где табличная функция tvfUtilGenerateIntegerList определена как
<br/>-- Example Inputs
<br/>
<br/>-- DECLARE @StartInt int
<br/>-- DECLARE @Increment int
<br/>-- DECLARE @Iterations int
<br/>-- SET @StartInt = 56200
<br/>-- SET @Increment = 1
<br/>-- SET @Iterations = 400
<br/>-- DECLARE @tblResults TABLE
<br/>-- (
<br/>-- IterationId int identity(1,1),
<br/>-- GeneratedInt int
<br/>-- )
<br/>
<br/>
<br/>-- =============================================
<br/>-- Author: 6eorge Jetson
<br/>-- Create date: 11/22/3333
<br/>-- Description: Generates and returns the desired list of integers as a table
<br/>-- =============================================
<br/>CREATE FUNCTION [dbo].[tvfUtilGenerateIntegerList]
<br/>(
<br/> @StartInt int,
<br/> @Increment int,
<br/> @Iterations int
<br/>)
<br/>RETURNS
<br/>@tblResults TABLE
<br/>(
<br/> IterationId int identity(1,1),
<br/> GeneratedInt int
<br/>)
<br/>AS
<br/>BEGIN
<br/>
<br/> DECLARE @counter int
<br/> SET @counter= 0
<br/> WHILE (@counter < @Iterations)
<br/> BEGIN
<br/> INSERT @tblResults(GeneratedInt) VALUES(@StartInt + @counter*@Increment)
<br/> SET @counter = @counter + 1
<br/> END
<br/><br>
<br/> RETURN
<br/>END
<br/>--Debug
<br/>--SELECT * FROM @tblResults</p>
<p>