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

  • SEARCH
  • Home
  • 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 7915501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:28:35+00:00 2026-06-03T14:28:35+00:00

Im kinda new to SQL Server and am using the 2005 version. What I

  • 0

Im kinda new to SQL Server and am using the 2005 version.

What I need to be able to do is calculate the number of repeat calls that come in.

The table I have called EP_Call_Int has columns called “Daily_Dispo_Date” (datetime) , “Login” (nvarchar(35)), “Policy” (int), “Dispo” (Nvarcar(50)) and has data that looks like this:

Daily_Dispo_Date     Login    Policy  Dispo
2012-03-01 10:31:54  b_smith  42484   Cancellation
2012-03-01 10:45:12  s_tomas  48424   Payment
2012-03-01 11:01:32  b_smith  41546   Billing Question
2012-03-01 11:04:34  s_tomas  42484   Cancellation
2012-03-01 11:15:42  d_jones  48425   Payment
2012-03-01 11:50:02  d_jones  48425   Billing Question
2012-03-01 13:02:09  b_smith  48425   Billing Question
2012-03-02 10:31:54  d_jones  42489   Payment
2012-03-02 10:45:12  s_tomas  48434   Cancellation
2012-03-02 11:01:32  d_jones  41540   Payment
2012-03-02 11:04:34  s_tomas  41546   Billing Question
2012-03-02 11:15:42  d_jones  48417   Payment
2012-03-02 11:50:02  d_jones  44525   Billing Question
2012-03-02 13:02:09  s_tomas  41546   Billing Question
2012-03-03 10:31:54  d_jones  42089   Cancellation
2012-03-03 10:45:12  s_tomas  48434   Cancellation
2012-03-03 11:01:32  d_jones  41440   Cancellation
2012-03-03 11:04:34  s_tomas  41646   Payment
2012-03-03 11:15:42  d_jones  48817   Payment
2012-03-03 11:50:02  d_jones  41546   Payment
2012-03-03 13:02:09  s_tomas  41446   Payment

I have all the test data in a SQL Fiddle Link http://sqlfiddle.com/#!3/0de9c

What im trying to do is count the number of repeat calls our company gets. How I need to count them is by using a time range of 5 minutes to 3 days. So the firstdate will be the first time that person calls in, if they call in again it cant count as a double hit against the same person.

So what im trying to get my final result to look like is:

Daily_Dispo_Date    Dispo             Total_Calls   Total_Repeating
2012-03-01          Cancellation      2             1
2012-03-01          Payment           2             0
2012-03-01          Billing Question  3             2
2012-03-02          Payment           3             0
2012-03-02          Cancellation      1             1
2012-03-02          Billing Question  3             2
2012-03-03          Cancellation      3             0
2012-03-03          Payment           3             0

The Query I have so far looks like this:

DECLARE @Start DATETIME, @End DATETIME
SET @Start = '20120401'
SET @End = '20120403'
;With [Find_First_Call] As
(
  Select 
     [Policy]
    ,[Dispo]
    ,Min([Daily_Dispo_Date]) As [Call_Date] --need to figure out how to have reset after each call
  From [EP_Call_Int]
  Group By [Policy], [Dispo]
)
Select 
  DateAdd(dd, DateDiff(dd, 0, [Daily_Dispo_Date]), 0) As [Daily_Dispo_Date]
, [Dispo]
, Count([Dispo]) As [Total_Calls]
,(
 Select
   Count([EP_Call_Int2].[Dispo])
 From [EP_Call_Int] as [EP_Call_Int2]
   Left Join [Find_First_Call] as [Find_First_Call] On [Find_First_Call].[Policy] = [EP_Call_Int].[Policy]
   And [Find_First_Call].[Dispo] = [EP_Call_Int].[Dispo]
 Where [EP_Call_Int2].[Daily_Dispo_Date] >= DateAdd(n, 5, [Find_First_Call].[Call_Date])
   And [EP_Call_Int2].[Daily_Dispo_Date] <= DateAdd(dd, 3, [Find_First_Call].[Call_Date])
   And DateAdd(dd, 0, [EP_Call_Int].[Daily_Dispo_Date]), 0) = DateAdd(dd, 0, [EP_Call_Int2].[Daily_Dispo_Date]), 0)
) As [Total_Repeat_Calls]
From [EP_Call_Int]
Where [Daily_Dispo_Date] Between @Start And @End
And [Policy] Like '[4]____'
Group By DateAdd(dd, [Daily_Dispo_Date], 0), [Dispo]
Order By [Daily_Dispo_Date], [Total_Calls] Desc

So in short if someone calls in 3 times over the course of 3 days for the same reason it will count as 2 call backs. If they call on day 1, 2, and 3 i need it to show a repeat on day 1 and 2.

  • 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-03T14:28:36+00:00Added an answer on June 3, 2026 at 2:28 pm

    I’m not sure I got all the rules right, but I think this might do it:

    ;with Call_ordinal_no as (
      select 
        convert(date, [Daily_Dispo_Date]) as CallDate,
        [Login],
        [Dispo],
        row_number() over (
          partition by 
            convert(date, [Daily_Dispo_Date]),
            [Login],
            [Dispo]
          order by [Daily_Dispo_Date]
        ) as CallNumber
      from [EP_Call_Int]
    )
    select 
      CallDate as Daily_Dispo_Date,
      Dispo,
      count(*) as Total_Calls,
      sum(case when CallNumber > 1 then 1 else 0 end) as Total_Repeating
    from Call_ordinal_no
    group by CallDate, Dispo
    order by CallDate;
    

    SQLFiddle: http://sqlfiddle.com/#!3/0de9c/34

    Update:

    After discussing the rules in more depth, I think this is the correct SQL:

    ;with calls as (
      select 
        DateAdd(dd, DateDiff(dd, 0, c.[Daily_Dispo_Date]), 0) as CallDate,
        c.[Login],
        c.[Dispo],
        c.[Policy],
        case 
          when first.[Login] is null then 0
          else 1 
        end as IsRepeat
      from [EP_Call_Int] c
      left join [EP_Call_Int] first
        on c.[Login] = first.[Login]
        and c.[Dispo] = first.[Dispo]
        and c.[Policy] = first.[Policy]
        and datediff(minute, first.[Daily_Dispo_Date], c.[Daily_Dispo_Date])
          between 5 and 3 * 24 * 60
    )
    select 
      CallDate,
      Dispo,
      count(*) as Total_Calls,
      sum(IsRepeat) as Total_Repeating
    from calls
    group by CallDate, Dispo
    order by CallDate, Dispo
    

    SQLFiddle: http://sqlfiddle.com/#!3/0de9c/69

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

Sidebar

Related Questions

using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; Kinda new at C# here.. I got the first row
I'm new to using SQL Server 2008 DB Project's in VS 2010. I found
I am using VS2005 C# and SQL Server 2005. I have an Excel file
I need to backup database (using SQL Server 2008 R2). Size of db is
I'm working in Microsoft SQL Server 2005 and need to do an analysis of
Currently, I need to be able to retrieve values from an SQL Server DB,
I am new to schema, roles and user management part in sql server. Till
SQL Server 2005. I want a script to run in the near future when
I have an ASP.NET MVC 3 application with a SQL Server 2005 database backend.
I'm using a SQL Server 2008 Database Project, and I'm finding it's very cumbersome

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.