我有以下2個程序,我將其用作報告的來源。截至目前,我在SQL Server Reporting Services 2008 R2報告中呈現了兩個不同的表格,因爲它們不允許我將它們放在一起,因爲它們屬於2個不同的數據集。如何編寫JOIN語句以合併來自不同表格的數據
我想將它們呈現在單個表格中,但我沒有成功嘗試在此處使用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
在AgentActivityLog
= UserId
)
列: 從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
和值,必須將它們合計並「轉換」爲列。
它的複雜,我相信......
我想我可以管理WHERE子句,但不能管理GROUP BY。順便說一句,你的意思是AgentActivityLog.UserId。 – Amarundo
我會嘗試。會回到你身邊。 – Amarundo
這不起作用。例如:在JOIN之前,某個用戶和日期的Sum(nAnswered)爲17.在JOIN之後,值爲808,809。原因不僅在於WHERE子句中的篩選器未被評估,而且JOIN是記錄乘以種類。 – Amarundo