Run this to see if it gives you close to what you are looking for. May need some work.DECLARE @startDate DATE = '20140101', @endDate DATE = '20151231'; SELECT DATEADD(mm,Number,@StartDate) AS [Date], SUM( CASE WHEN Start_date <= DATEADD(mm, s.number, @startDate) AND ISNULL(End_date, '20991231') >= DATEADD(mm, s.number, @startDate) THEN 1 ELSE 0 END )FROM client_Program c CROSS APPLY ( SELECT Number FROM master..spt_values s WHERE DATEADD(mm,Number,@StartDate) <= @endDate AND s.TYPE = 'P' ) sGROUP BY NumberORDER BY [Date];