I leave were the correct answer based on the help of everyone
-- dummy data
declare @table table
(
DAY datetime,
QTY int,
Name nvarchar (500) NULL
)
insert @table values('2010-1-1', 1, 'jack')
insert @table values('2010-1-3', 5, 'jack')
insert @table values('2010-1-2', 3 , 'wendy')
insert @table values('2010-1-6', 2 , 'wendy')
-- algorithm
DECLARE @output TABLE (
DAY datetime,
Qty int,
Name varchar(25)
)
DECLARE @minMonth datetime, @maxMonth datetime, @lastName varchar(25)
SET @minMonth = '2010-1-1'
SET @maxMonth = '2010-1-6';
WITH cte AS (
SELECT @minMonth AS DateValue
UNION ALL
SELECT DATEADD(day, 1, DateValue)
FROM cte
WHERE DATEADD(day, 1, DateValue) <= @maxMonth
)
INSERT INTO @output
SELECT
cte.DateValue,
ISNULL(tbl.qty,0),
tbl.Name
FROM
cte cross JOIN
@table tbl
update @output
set qty = 0
where cast(DAY as nvarchar)+'@'+cast(Qty as nvarchar)+'@'+Name in
(
select cast(DAY as nvarchar)+'@'+cast(Qty as nvarchar)+'@'+Name from @output
except
select cast(DAY as nvarchar)+'@'+cast(Qty as nvarchar)+'@'+Name from @table
)
SELECT DAY, sum(qty) as qty, Name
FROM @output
GROUP BY DAY, Name
order by 3,1
and the output that I pretend
2010-01-01 00:00:00.000 1 jack
2010-01-02 00:00:00.000 0 jack
2010-01-03 00:00:00.000 5 jack
2010-01-04 00:00:00.000 0 jack
2010-01-05 00:00:00.000 0 jack
2010-01-06 00:00:00.000 0 jack
2010-01-01 00:00:00.000 0 wendy
2010-01-02 00:00:00.000 3 wendy
2010-01-03 00:00:00.000 0 wendy
2010-01-04 00:00:00.000 0 wendy
2010-01-05 00:00:00.000 0 wendy
2010-01-06 00:00:00.000 2 wendy
Although the solution is correct, doesn't fit my need because recursion limitation.
Hopefully this script will help anyone with similar questions
Thank you to all