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 1092557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:42:02+00:00 2026-05-16T23:42:02+00:00

I have this table named OrdersToCall Data types: All bigints, except for date which

  • 0

I have this table named OrdersToCall

Data types: All bigints, except for date which is a datetime

|-Order Num-|----Date--- |- Primary Ph -| Secondary Ph | Alternate Ph
|----101----| 02-07-2010 | 925-515-1234 | 916-515-1234 |  707-568-5778  
|----102----| 02-07-2010 | 925-888-4141 | 925-888-4141 |  000-000-0000
|----103----| 02-07-2010 | 000-000-0000 | 000-000-0000 |  510-555-4575  
|----104----| 02-07-2010 | 415-789-5454 | 415-707-5588 |  735-874-9566
|----105----| 02-07-2010 | 925-887-7979 | 925-887-7979 |  925-887-7979

and I have another table named PhoneNumCalled

|-AgentID-|----Date----|-Dialed Number|
|-145564--| 02-07-2010 | 925-515-1234 |
|-145564--| 02-07-2010 | 707-568-5778 |
|-145566--| 02-07-2010 | 925-888-4141 |
|-145567--| 02-07-2010 | 510-555-4575 |
|-145568--| 02-07-2010 | 415-789-5454 |
|-145568--| 02-07-2010 | 415-707-5588 |
|-145568--| 02-07-2010 | 735-874-9566 |
|-145570--| 02-07-2010 | 925-887-7979 |
|-145570--| 02-07-2010 | 925-887-7979 |

Now my challenge is: I want to count how many Order Num were called and create a table based off the results.

So for example if agent 1234 called all 3 numbers on 1 order that would still only count as 1 order for that agent. The ratio is 1:1. Once a phone number is called then it is counted as 1 order. No matter if all 3 were called, an agent only has to call 1 of phone numbers to get credit for the order.

In less than 3 months time I already have almost 1/2 a million records so try to be as space conscious as possible.

My solution (Which I wish to revise with your help):
I ended up creating a stored procedure which:

--Delete and recreate the CombinedData table created yesterday
Insert into the CombinedData table
Select Order Num, Date, Primary Ph as Phone
 from OrdersToCall
Union
Select Order Num, Date, Secondary Ph as Phone
 from OrdersToCall
Union
Select Order Num, Date, Alternate Ph as Phone
 from OrdersToCall
Delete from the CombinedData table
 where phone in ('000-000-0000', '999-999-9999')

Now not only does this create a new table, but since each phone number in each order is now its own row the table becomes HUGE and take up to 2 minutes to create.

Then from this table I derive the counts and store those in yet another table.

  • 1 1 Answer
  • 3 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-05-16T23:42:02+00:00Added an answer on May 16, 2026 at 11:42 pm

    I think this is what you’re looking for:

    SELECT c.AgentId, COUNT(DISTINCT o.[Order Num]) AS [Orders per Agent]
    FROM OrdersToCall o
    JOIN PhoneNumCalled c ON c.[Dialed Number] = o.[Primary Ph]
                          OR c.[Dialed Number] = o.[Secondary Ph]
                          OR c.[Dialed Number] = o.[Alternate Ph]
    GROUP BY c.AgentId
    

    If you want to know how many calls were made on each date, you would have to join on the date also:

    SELECT c.AgentId, c.Date, COUNT(DISTINCT o.[Order Num]) AS [Orders per Agent]
    FROM OrdersToCall o
    JOIN PhoneNumCalled c ON (c.[Dialed Number] = o.[Primary Ph]
                          OR c.[Dialed Number] = o.[Secondary Ph]
                          OR c.[Dialed Number] = o.[Alternate Ph])
                          AND o.Date = c.Date
    GROUP BY c.AgentId, c.Date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table named tree1, which has a table names student_details.This table
I have this table named categories with three fields as below cat | order
I have a table named datas and I'm executing a query like this: SELECT
I have a table named size here, something like this: size id | size
I have this table named sample with these values in MS Sql Server: ID
I have a table named 'Attendance' which is used to record student attendance time
I have a table named categories like this: id int(11) NO PRI NULL auto_increment
I have a table named b having a column j which is varchar(3) where
I have a table named Template which I set my messages to send them
I have a table named user. This table has a foreign key to 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.