我想在本报告的末尾添加一个额外的列来计算YTD。任何建议将不胜感激。
declare @startDate datetime = '6/01/2015';
declare @endDate datetime = '6/30/2015'; --inclusive
declare @ytdstart datetime = '1/1/2015';
declare @ytdend datetime = '6/30/2015'; -- inclusivve
declare @officeID int = null; --replace with a value if you only want to show a specific office
select o.name,
sum(isnull(rpt.transcriptionlinecount,0)) as 'Monthly Lines'
from office as o
left join RptLineCountInfo as rpt on rpt.officeID = o.officeID
and rpt.finishedTime between @startDate and @endDate + 1
where
rpt.officeID = case when @officeID is null then rpt.officeID else @officeID end
and (rpt.dictationStatus != 'd' and rpt.dictationstatus != 'q')
and (rpt.officeID != '2' and rpt.officeID != '1' and rpt.officeID != '60') or rpt.transcriptionLineCount IS NULL
group by
o.name
order by
o.name