sql server - SQL - have full range of dates when units id is null /0 -


i building query count number of units of product , product b , total value amount series of dates. days have 1 or more units of product product b can have 0 units in days. i've joined product b table product table on date column. i've used clause count number of product b units. aggregation of units correct, however, want know how can 'add' days in range below instance not retrieved query, days there no units of product b - 08/08/16, 10/08/16 show in table below ( table below retrieved rows of query).

date        unit_a   unit_b  amount 07/08/16    24         1     48 09/08/16    62         17   207 11/08/16    52         12   102 12/08/16    31         5    152 16/08/16    32         12   110 17/08/16    30         3    120 18/08/16    43         41   315 19/08/16    20         1    50.12 21/08/16    19         12   48 22/08/16    35         1    32 

here example of query trying create:

with prod_a as(     select cast(a.date_started date) a_date,     count(a.id) id_a     table_a     group cast(a.date_started date) ,a.id_a  ) select cast(b.date_started date) b_date,      count(case when b.id not null id_b else null end) units_b,     case when cond1=something isnull(sum(table_b.price),0) else null end amount,  table_b b left join prod_a     on prod_a.a_date = b.b_date  cast(b.b_date date) >= dateadd(day,-21,getdate()) group cast(b.b_date date) 

please let me know if have suggestions achieve this. 1 solution create dummy table (with clause) of dates in range trying not take route or add case main select statement insert 0 instead of null when there no b.id.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -