I need to do a daily sum, in the last 30 days. I have this query that fetches data from two tables, but if exists a date in the second table (CabCC) and there is not in first table (CabFT), the value is not shown. How can I change the query to automatically generate the last 30 days in Select Datedoc.
SUM(CASE WHEN Type='FT' AND Anl = 0 THEN isnull(value*cota,0) END) AS 'Invoice',
(SELECT sum(Valuedoc)from CabCC where DateDocF=CabFT.Datedoc) as 'Rec'
group BY Datedoc
ORDER BY Datedoc desc