我得到了这个代码,它目前根据给定的标准对呼叫中心进行排名。我的任务是将此排名从基于中心更改为副总监(AKA AD、经理、BottomUpLevel02)。
问题是,我没有很多实际创建表格的经验。我通常会操纵视图,所以我确信这里有一些我严重缺乏的语法规则。
这是代码:
SET NOCOUNT ON
DECLARE @StartDate SMALLDATETIME,
@EndDate SMALLDATETIME
SET @StartDate = '2012/07/01'
SET @EndDate = '2012/07/31'
IF OBJECT_ID('tempdb..#ACSResults') IS NOT NULL DROP TABLE #ACSResults
CREATE TABLE #ACSResults (AreaID VARCHAR(4), Location VARCHAR(50),
MonthName VARCHAR(6),
RepResolve FLOAT, ERP FLOAT)
INSERT INTO #ACSResults
SELECT a.area, a.location,
a.monthname,
CASE WHEN SUM(CASE WHEN a.RepResolve IN ('1','0')
THEN 1
ELSE 0 END) = 0
THEN NULL
ELSE CAST(SUM(CASE WHEN a.RepResolve = '1'
THEN 1
ELSE 0 END)AS FLOAT) / CAST(SUM(CASE WHEN a.RepResolve IN ('1','0')
THEN 1
ELSE 0 END) AS FLOAT) END AS REPRESOLVE,
CASE WHEN SUM(CASE WHEN a.ERP IN ('0','1','2','3','4','5','6','7','8', '9', '10')
THEN 1
ELSE 0 END) = 0
THEN NULL
ELSE (CAST(SUM(CASE WHEN a.ERP IN ('8', '9', '10')
THEN 1
ELSE 0 END) AS FLOAT) / CAST(SUM(CASE WHEN a.ERP in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')
THEN 1
ELSE 0 END) AS FLOAT))END AS ERP
FROM (SELECT CASE WHEN vl.virtuallocationtypeid =13
THEN 'PP'
WHEN eh.PeopleSoftDepartmentID IN ('2922', '9050', '9136', '9130','9134','9135', '9137', '9060')
THEN 'FS'
WHEN eh.PeopleSoftDepartmentID ='2390'
THEN 'CMO'
WHEN eh.virtuallocationtypeid = 3
OR eh.peoplesoftDepartmentid IN ('9165', '9166','9157','9167','<<OSVBSC>>')
THEN 'BSC'
WHEN (eh.virtuallocationid IN ('111', '113', '114', '115', '116', '118', '119', '120', '122', '123')
AND acs.OfferDate < '04/01/2011')
OR (eh.virtuallocationid IN ('116','120','123')
AND acs.OfferDate >= '04/01/2011')
THEN 'SPC2'
WHEN (eh.virtuallocationid IN ('112', '121', '110')
AND acs.OfferDate >= '07/01/2011')
THEN 'SPC2'
WHEN (eh.virtuallocationid IN ('99')
AND acs.OfferDate < '07/01/2011')
AND eh.PeopleSoftDepartmentID IN ('9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>')
THEN 'SPC2'
WHEN eh.EmployeeTypeID = 'V'
THEN 'SPC'
WHEN vl.virtuallocationtypeid =14
THEN 'SPC2'
WHEN (eh.virtuallocationID IS NULL
AND eh.AreaId IS NULL)
THEN eh.PeopleSoftAreaID
WHEN eh.virtuallocationID IS NULL
THEN eh.AreaID
ELSE vl.AreaId END AS Area,
CASE WHEN eh.VirtualLocationID = 102
THEN 'HQ Quality - GSC'
WHEN eh.peoplesoftDepartmentid IN ('9165', '9166','9167')
THEN 'GSC'
WHEN eh.peoplesoftdepartmentid ='<<OSVAOL>>'
AND eh.virtuallocationid =64
THEN 'ALORICA AOL'
WHEN (eh.virtuallocationid IN ('99', '148')
AND eh.PeopleSoftDepartmentID IN ('9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>'))
THEN 'Wichita Falls (WDS) - Tech'
WHEN eh.virtuallocationID IS NULL
OR vl.VirtualLocationTypeID = 4
THEN 'Others'
ELSE vl.VirtualLocationDescription END AS Location,
CASE WHEN eh.PeopleSoftDepartmentID IN ( '9180', '<<WEBILING>>','<<OSVSPN>>')
THEN 'Bilingual'
WHEN eh.PeopleSoftDepartmentID IN ( '9150', '9440', '9370', '9260', '9330', '9460','9155','9215','9157','9175','<<OSVBSC>>')
THEN 'BSC'
WHEN eh.PeopleSoftDepartmentID IN ( '9395', '9010', '9341', '9340', '9450', '9131', '9025', '10014901', '<<SO_WEVIS>>', '<<WE_MWVIS>>', '<<WEVIS>>', '<<NEVIS>>', '<<OSCCALTEL>>', '<<SOVIS>>', '<<NE_MWVIS>>', '<<MWVIS>>', '<<OSVCS>>')
THEN 'Care'
WHEN eh.PeopleSoftDepartmentID IN ('9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>' )
THEN 'Tech'
WHEN eh.PeopleSoftDepartmentID IN ('<<AOL_WEVIS>>', '<<OSVAOL>>')
THEN 'AOL'
WHEN eh.peoplesoftdepartmentid IN ('<<OSVCS_TCS>>', '<<OSVOB_TCS>>')
THEN 'New Hire Transition'
WHEN eh.PeopleSoftDepartmentID = '9390'
THEN 'EPP'
WHEN eh.PeopleSoftDepartmentID = '9120'
THEN 'ERT'
WHEN eh.PeopleSoftDepartmentID = '9190'
THEN 'IRT'
WHEN eh.PeopleSoftDepartmentID = '9085'
THEN 'Bilingual Tech'
WHEN eh.PeopleSoftDepartmentID IN ('9490', '<<LNP>>','<<OSVLNP>>')
THEN 'LNP'
WHEN eh.PeopleSoftDepartmentID = '9070'
THEN 'Retention'
WHEN eh.PeopleSoftDepartmentID = '9115'
THEN 'GLOBAL'
WHEN eh.PeopleSoftDepartmentID IN ('<<ONEBILL>>', '<<OSVOB>>')
THEN 'Onebill'
WHEN eh.peoplesoftdepartmentid = '<<PPCARE>>'
THEN 'Prepaid Care'
WHEN eh.peoplesoftdepartmentid = '<<PPTECH>>'
THEN 'Prepaid Tech'
ELSE 'Other' END AS DeptGroup,
psd.PeopleSoftDepartmentDescription AS Dept,
acs.IVRCallID,
acs.OfferDate,
acs.EmployeeID,
acs.ACSSUserID,
Cast(acs.DidRepResolve as Float) As RepResolve,
acs.Question1 AS FCR,
acs.Question2 AS ERP,
acs.Question3 AS NPS,
acs.ACSSCallID,
month (acs.Offerdate) AS MonthName
FROM dbCustomerSurvey.Detail.vwAfterCallSurvey acs
LEFT JOIN dbEmployee.Summary.vwEmployeeHistory eh
ON acs.EmployeeID = eh.EmployeeID
AND acs.OfferDate BETWEEN eh.StartDate
AND eh.EndDate
LEFT JOIN dbEmployee.Config.vwName Rep
ON eh.EmployeeID = Rep.EmployeeID
LEFT JOIN dbEmployee.Config.vwName Sup
ON eh.BottomUp01ID = Sup.EmployeeID
LEFT JOIN dbEmployee.Config.vwName Mgr
ON eh.BottomUp02ID = Mgr.EmployeeID
LEFT JOIN dbEmployee.Config.vwName Dir
ON eh.BottomUp03ID = Dir.EmployeeID
LEFT JOIN dbEmployee.Config.vwVirtualLocation vl
ON eh.VirtualLocationID = vl.VirtualLocationID
LEFT JOIN dbEmployee.Config.vwDepartment d
ON eh.DepartmentID = d.DepartmentID
LEFT JOIN dbEmployee.Config.vwPeopleSoftDepartment psd
ON eh.PeopleSoftDepartmentID = psd.PeopleSoftDepartmentID
WHERE acs.CurrentStatus IN ('Completed', 'COMP')
AND acs.surveytype IN ('ACS_FCR_Rep_Perform', 'ACS_FCR_Rep_Perform-prepaid', 'ACS_Rep_Perform_BSC2', 'ACS_Rep_Perform_Gov')
AND acs.OfferDate BETWEEN @StartDate AND @EndDate) a
WHERE a.Area IN ('WE', 'mw','ne','so')
AND a.Location NOT IN ('West Area Staff - CS', 'Northeast Area Staff - CS', 'Midwest Area Staff - CS', 'Others', 'West Area Finance - CS', 'Midwest Area Marketing, Sales, & Training', 'South Area Staff - CS', 'Midwest Area Finance - CS', 'Bellevue - CS')
AND a.deptgroup in ('aol','bilingual','Bilingual Tech','care','global','lnp', 'onebill','other','retention','tech', 'new hire transition')
GROUP BY a.area, a.location, a.monthname
-- 重复表
IF OBJECT_ID('tempdb..#HRRep') IS NOT NULL DROP TABLE #HRRep
CREATE TABLE #HRRep (AreaID VARCHAR(4), Location VARCHAR(50),
MonthName VARCHAR(6),
HourRepeatPercent FLOAT)
INSERT INTO #HRRep (AreaID, Location, MonthName, HourRepeatPercent)
SELECT eh.AreaID, vl.VirtualLocationDescription,
MONTH (acs.statdate) AS MonthName,
CAST(SUM(acs.Repeats2Hr)as FLOAT) / NULLIF(SUM(acs.Calls2Hr), 0) as 'HourRepeatPercent'
FROM dbReportSummary.ReportSummary.vwRepeatCalls2Hr acs WITH (NOLOCK)
LEFT JOIN dbEmployee.Summary.vwEmployeeHistory eh WITH (NoLOCK)
ON acs.EmployeeID = eh.EmployeeID
AND acs.StatDate BETWEEN eh.StartDate AND eh.EndDate
LEFT JOIN dbEmployee.Config.vwVirtualLocation vl
ON eh.VirtualLocationID = vl.VirtualLocationID
LEFT JOIN dbEmployee.Config.vwDepartment d
ON eh.DepartmentID = d.DepartmentID
LEFT JOIN dbEmployee.Config.vwPeopleSoftDepartment psd
ON eh.PeopleSoftDepartmentID = psd.PeopleSoftDepartmentID
WHERE acs.StatDate BETWEEN @StartDate AND @EndDate
AND eh.PeopleSoftDepartmentID IN ('9180', '<<WEBILING>>','<<OSVSPN>>', '9150', '9440', '9370', '9260', '9330', '9460','9155','9215','9157','9175','<<OSVBSC>>', '9395', '9010', '9341', '9340', '9450', '9131', '9025', '10014901', '<<SO_WEVIS>>', '<<WE_MWVIS>>', '<<WEVIS>>', '<<NEVIS>>', '<<OSCCALTEL>>', '<<SOVIS>>', '<<NE_MWVIS>>', '<<MWVIS>>', '<<OSVCS>>', '9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>', '<<AOL_WEVIS>>', '<<OSVAOL>>', '<<OSVCS_TCS>>', '<<OSVOB_TCS>>' , '9390', '9120', '9190', '9085', '9490', '<<LNP>>', '<<OSVLNP>>', '9070', '9115', '<<ONEBILL>>', '<<OSVOB>>', '<<PPCARE>>', '<<PPTECH>>')
AND eh.AreaID IN ('MW', 'NE', 'SO', 'WE')
AND vl.VirtualLocationDescription NOT IN ('West Area Staff - CS', 'Northeast Area Staff - CS', 'Midwest Area Staff - CS', 'Others', 'West Area Finance - CS')
AND eh.Titleid IN ('1','2','3','509')
GROUPBY eh.AreaID, vl.VirtualLocationDescription, MONTH (acs.statdate)
-- (?) --
SELECT a.Location, a.RepResolve, a.RRRank, a.ERP, a.ERPRank,a.HourRepeatPercent,
a.RepeatRank, (a.RRRank + a.ERPRank+a.RepeatRank) as 'Total Rank Points',
RANK() OVER(ORDER BY (a.RRRank + a.ERPRank+a.RepeatRank) ASC, a.RepResolve DESC) AS 'Overall Rank'
FROM (SELECT a.Location, a.RepResolve,
RANK() OVER(ORDER BY a.RepResolve DESC) AS RRRank, a.ERP,
RANK() OVER(ORDER BY a.ERP DESC) AS ERPRank, b.HourRepeatPercent,
RANK() OVER(ORDER BY b.HourRepeatPercent ASC) AS RepeatRank
FROM #ACSResults AS A
LEFT JOIN #HRRep AS B
ON a.areaid = b.areaid
AND a.monthname = b.monthname
AND a.location = b.location) a
GROUP BY a.Location, a.RepResolve, a.RRRank, a.ERP, a.ERPRank,a.HourRepeatPercent,
a.RepeatRank, (a.RRRank + a.ERPRank + a.RepeatRank)
当我尝试将 AD 添加到组合中时,我不断收到有关 select 子句与 insert 子句不匹配的错误。任何人都可以指出需要修改以包含 AD 的区域吗?
编辑:我能够成功添加一个广告列!新问题:结果有点偏离。在根据位置对结果进行排名之前,每个不同的位置都会根据总点数分配一个排名。它很干净,数字加起来了。现在有重复的AD,排名倒退(总排名积分最少的被列为第一名)。
我只是将 AD 列添加到 INSERT 语句和 select 语句中。谁能告诉我,除了在查询的适当位置添加 AD 列之外,我是否应该修改查询的任何操作或功能以反映给定日期范围的真实排名?请随时要求对此的任何部分进行澄清。提前感谢您提供的任何帮助。