Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query for Fiscal Year Data

Author  Topic 

daviss5
Starting Member

2 Posts

Posted - 2014-03-17 : 13:52:59
Good Morning, I am using the query below and it is working great to give me montly averages. I need to find the fiscal year to date averages for the same data. I think all I should need to change is the Select and Group by sections but I am having no sucess.

Any help is appricated.

SELECT Format([CallDate],"yyyy mmm") AS [Month], Count(DailyCallStats.CallDate) AS CountOfCallDate, DailyCallStats.Agent, Avg(DailyCallStats.Inbound) AS AvgOfInbound, Avg(DailyCallStats.Outbound) AS AvgOfOutbound, Avg(DailyCallStats.TotalCalls) AS AvgOfTotalCalls, Avg(DailyCallStats.AvgWrap) AS AvgOfAvgWrap, Avg(DailyCallStats.ParkTime) AS AvgOfParkTime
FROM DailyCallStats
GROUP BY Format([CallDate],"yyyy mmm"), DailyCallStats.Agent, Format([CallDate],"yyyy mm")
ORDER BY Format([CallDate],"yyyy mm");

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-03-18 : 07:41:52
When is your fiscal year?
Also, the FORMAT function is very very very very very slow.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

daviss5
Starting Member

2 Posts

Posted - 2014-03-18 : 11:53:30
The fiscal year is April through March. And I am pretty new to SQL so if there is a better way I am open to it.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-03-18 : 17:54:25
So January, February and March belongs to the fiscal year the year before?



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-03-18 : 18:02:05
Try this
SELECT		CallMonth AS [Month], 
COUNT(CallMonth) AS CountOfCallDate,
Agent,
AVG(Inbound) AS AvgOfInbound,
AVG(Outbound) AS AvgOfOutbound,
AVG(TotalCalls) AS AvgOfTotalCalls,
AVG(AvgWrap) AS AvgOfAvgWrap,
AVG(ParkTime) AS AvgOfParkTime
FROM (
SELECT DATEPART(YEAR, DATEADD(MONTH, -3, CallDate)) AS FiscalYear,
DATENAME(MONTH, CallDate) AS CallMonth,
DATEDIFF(MONTH, 0, CallDate) AS SortOrder,
Agent,
Inbound,
Outbound,
TotalCalls,
AvgWrap,
ParkTime
FROM dbo.DailyCallStats
) AS d
GROUP BY FiscalYear,
CallMonth,
SortOrder
ORDER BY SortOrder;



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -