|
--try
declare @dt1 datetime, @dt2 datetime
select @dt1='2016-12-01', @dt2='2017-02-01'
declare @T table([date] datetime)
while @dt1<=@dt2
begin
insert @T select @dt1
set @dt1=@dt1+5
end
SELECT A.[date] as SDate, isnull(sum(SaleGroup), 0) as SaleGroup, isnull(sum(SzG), 0) as SzG
FROM @T as A
left join dbo.Saleday Dbo_saleday as B on B.SDate between A.[date] and A.[date]+5
WHERE B.SDate between @dt1 and @dt2
GROUP BY A.[date] |
|