CREATE procedure EnquiryAdmission as
create table #Calendar
(Months date)
insert INTO #Calendar VALUES('1/1/2014'),('2/1/2014'),('3/1/2014'),('4/1/2014'),('5/1/2014'),('6/1/2014'),('7/1/2014'),('8/1/2014'),('9/1/2014'),('10/1/2014'),('11/1/2014'),('12/1/2014')
BEGIN
SELECT datename(mm,cal.months), COUNT(DISTINCT enqno) AS Enquiries,count(DISTINCT learnerid)AS Admissions
FROM #calendar cal
LEFT JOIN enquiry e
ON Month(cal.Months) = Month([enquiry date]) AND ((YEAR([enquiry date])=YEAR(GetDate())) OR [enquiry date] IS NULL)
LEFT JOIN admission
ON Month(cal.Months)=Month(Date) AND ((YEAR(date)=YEAR(GetDate())) OR date IS NULL)
GROUP BY cal.Months
END