Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:33:27+00:00 2026-06-16T15:33:27+00:00

I have the following 2 procedures that I use as my source for a

  • 0

I have the following 2 procedures that I use as my source for a report. As of now, I’m presenting 2 different tables in my SQL Server Reporting Services 2008 R2 report, because it doesn’t let me put them together as they belong to 2 different data sets.

I want to present them in a single table, but I have not been successful trying to use JOIN here. How do I do that?

NOTE: cName in IAgentQueueStats corresponds to UserId in 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

And here is the second one:

/*** 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

BTW, if I take some time to comment/reply on your posts, it’s not lack of interest, but of understanding…

This is the report I want:
Rows: Person (= cName in IAgentQueueStats = UserId in AgentActivityLog)

Columns:
From IAgentQueueStats:

sum([nAnswered]) 
sum([nAnsweredAcd])
sum([tTalkAcd])
sum([nHoldAcd])
sum([tHoldAcd])
sum([tAcw])

From AgentActivityLog

The sum of 'Productive'

The sum of 'Not Your Fault'

The sum of 'Non Productive'

But note that 'Productive', 'Not Your Fault' and 'Non Productive' are values that repeat in rows for AgentId which implies many rows with same AgentId and value, that have to be totaled and “converted” to a column.

It’s complicated, I believe…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:33:28+00:00Added an answer on June 16, 2026 at 3:33 pm

    I couldn’t find a way to do it in one SQL statement, so I did it in a few steps, creating temporal tables in the stored procedure so that I could then JOIN the temporal tables and get the result I was looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have configured Reporting Services to allow users to use Report Builder application. Users
I have the following stored procedure in an SQL Server 2005 database (meant simply
I have the following SQL Server stored procedure : BEGIN TRAN CREATE TABLE #TempTable
I have several procedures that use the FileSystemObject. I find it's quite convenient. Question:
I have several stored procedures structured like the following: USE [WHouse] GO SET ANSI_NULLS
I have a few procedures that, for simplicity's sake, look like the following: public
I have the following situation. There is one central SQL Server (2008 R2, Standard
I have a SQL Server 2005 database that is suffering from lock starvation because
I have the following stored procedure that I have to get data from: EXECUTE
I have the following iBatis mapping for an Oracle Stored Procedure that returns a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.