I try this SQL query to get current total and also last 2 months records and current month record means total 3 months..
What I have tried:
Select distinct tblRv.Owner ,
DATENAME(MONTH,tblRe.StartDate) as [Month],
count(tblvv.VName)
as currentdata
from tblRe
inner join
tblRv on tblRe.RID=tblRv.RID
inner join
tblvv on tblRv.ID=tblvv.MID
where tblRe.StartDate>=DATEADD(MONTH,-3,GETDATE())
AND tblRe.EndDate<=GETDATE()
AND tblRe.Region='uk'
and tblRv.Owner='roh'
and VName <> ''
group by tblRv.Owner,
DATENAME(MONTH,tblRe.StartDate)
order by tblRv.Owner
this show me data like this
Owner Month currentdata
roh July 3
roh June 10
roh May 6
where as in my table data is like this
Owner Month currentdata
roh July 3
roh June 1
roh May 0
and formatting like thsi i want
Owner july june may
roh 3 1 0