Thanks Jorgen Unfortunately it not my database to add columns. I tried your query, but it was also slow, however that got me thinking more about the data I am querying. The vektronix table is actually quite large already after only a few months of production (about 8 rows for each unit produced) so I tried limiting the rows from vektronix in the where clause - that worked!
;WITH Dates AS
(
SELECT GETDATE()as DateValue
UNION ALL
SELECT DateValue -1
FROM Dates
WHERE DateValue -1 >= dateadd(d,-90,GETDATE())
)
SELECT convert(date,DateValue) as ProdDate , coalesce(trk.Tot,0)as ProdQty
FROM Dates D
left join (select convert(date,DateCreated) as TrkDate ,SUM(allocated) as Tot from vektronix.[dbo].[Tracking] t
where [TrackingTypeId] = '1' and DateCreated >= dateadd(d,-90,GETDATE())
group by convert(date,DateCreated))
as trk on trk.TrkDate = convert(date,DateValue)
group by DateValue,trk.Tot
order by datevalue desc
OPTION (MAXRECURSION 32747)
Thanks for your help!