我有以下2个程序用作报告的来源。截至目前,我在SQL Server Reporting Services 2008 R2报告中提供了2个不同的表,因为它不允许我将它们放在一起,因为它们属于2个不同的数据集。
我想将它们呈现在一个表中,但我没有成功尝试在这里使用JOIN。我该怎么做?
注意:cName
中的IAgentQueueStats
对应UserId
中的AgentActivityLog
。
/*** Aggregate values for Call Center Agents for calls, talk and hold time ***/
/*** The detail/row values is per 30-minute interval ***/
ALTER PROCEDURE [dbo].[sp_IAgentQueueStats_OnlyCalls_Grouped]
@p_StartDate datetime,
@p_EndDate datetime,
@p_Agents varchar(8000)
AS
SELECT [cName]
,sum([nAnswered]) SumNAnswered
,sum([nAnsweredAcd]) SumNAnsweredAcd
,sum([tTalkAcd]) SumTTalkAcd
,sum([nHoldAcd]) SumNHoldAcd
,sum([tHoldAcd]) SumTHoldAcd
,sum([tAcw]) SumTAcw
FROM [I3_IC].[dbo].[IAgentQueueStats]
WHERE dIntervalStart between @p_StartDate and DATEADD(s, 86400-1, @p_EndDate)
AND CHARINDEX ( cName ,@p_Agents)> 0
AND cReportGroup <> '*'
AND cHKey3 = '*' and cHKey4 ='*'
AND nEnteredAcd > 0
AND cReportGroup <> 'CCFax Email'
GROUP BY cName
这是第二个:
/*** Aggregate values for Call Center Agents for status/activity time ***/
/*** The detail/row values is per start-time/end-time ***/
ALTER PROCEDURE [dbo].[sp_AgentActivity_Grouped]
@p_StartDate datetime,
@p_EndDate datetime,
@p_Agents varchar(8000)
AS
SELECT [UserId],[StatusCategory],SUM([StateDuration]) [StatusDuration] FROM
(
SELECT
[UserId]
,[StatusGroup]
,[StatusKey]
, CASE [StatusKey]
WHEN 'Available' THEN 'Productive'
WHEN 'Follow Up' THEN 'Productive'
WHEN 'Campaign Call' THEN 'Productive'
WHEN 'Awaiting Callback' THEN 'Productive'
WHEN 'In a Meeting' THEN 'Not Your Fault'
WHEN 'Project Work' THEN 'Not Your Fault'
WHEN 'At a Training Session'THEN 'Not Your Fault'
WHEN 'System Issues' THEN 'Not Your Fault'
WHEN 'Test' THEN 'Not Your Fault'
WHEN 'At Lunch' THEN 'Non Productive'
WHEN 'Available, Forward' THEN 'Non Productive'
WHEN 'Available, Follow-Me' THEN 'Non Productive'
WHEN 'At Play' THEN 'Non Productive'
WHEN 'AcdAgentNotAnswering' THEN 'Non Productive'
WHEN 'Do Not Disturb' THEN 'Non Productive'
WHEN 'Available, No ACD' THEN 'Non Productive'
WHEN 'Away from desk' THEN 'Non Productive'
ELSE [StatusKey]
END StatusCategory
,stateduration
FROM [I3_IC].[dbo].[AgentActivityLog]
WHERE [StatusDateTime] between @p_StartDate and DATEADD(s, 86400-1, @p_EndDate)
AND CHARINDEX ( [UserId] ,@p_Agents)> 0
AND [StatusKey] not in ('Gone Home','Out of the Office','On Vacation','Out of Town')
) a
GROUP BY [UserId],[StatusCategory]
ORDER BY [UserId], [StatusCategory] desc
顺便说一句,如果我花一些时间评论/回复你的帖子,那不是缺乏兴趣,而是理解......
这是我想要的报告:
行:人员(cName
中的IAgentQueueStats
= UserId
中的AgentActivityLog
柱:
来自IAgentQueueStats
:
sum([nAnswered])
sum([nAnsweredAcd])
sum([tTalkAcd])
sum([nHoldAcd])
sum([tHoldAcd])
sum([tAcw])
来自AgentActivityLog
'Productive'
'Not Your Fault'
'Non Productive'
但请注意,'Productive'
,'Not Your Fault'
和'Non Productive'
是在AgentId
的行中重复的值,这意味着许多行具有相同的AgentId
和值,必须总计并“转换”为一列。
这很复杂,我相信......
答案 0 :(得分:1)
基本联接
select IAgentQueueStats.*, AgentActivityLog.*
from IAgentQueueStats
join AgentActivityLog
on IAgentQueueStats.cName = AgentActivityLog.UserId
这是一个开始 从那里需要知道你想要在这个组合报告中。
通过
尝试一个基本组select AgentActivityLog.UserId, AgentActivityLog.StatusCategory,SUM(AgentActivityLog.StateDuration),sum(IAgentQueueStats.nAnswered)
from IAgentQueueStats
join AgentActivityLog
on IAgentQueueStats.cName = AgentActivityLog.UserId
Group By AgentActivityLog.UserId, AgentActivityLog.StatusCategory
由于报告中的分组不同,因此不清楚如何做到这一点
一个是如上所述。
另一种是你把它分成两组,然后加入那个结果。
直到你定义报告无法知道哪个。
答案 1 :(得分:0)
我找不到在一个SQL语句中执行此操作的方法,所以我在几个步骤中完成它,在存储过程中创建时态表,以便我可以加入时态表并获得我正在查找的结果对