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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:02:09+00:00 2026-06-03T10:02:09+00:00

I am using SQL Server 2005. I am trying to gather information on 3

  • 0

I am using SQL Server 2005. I am trying to gather information on 3 different tables.

Table 1 is [User_Table] and looks like:

Lead  ID
1     5
1     8
1     12
2     13
2     14
2     15
2     18
2     24

Table 2 is [Interactions] and looks like:

Int_Date    ID  Interaction
2012-03-01  5   Hang Up
2012-03-01  13  Reset
2012-03-01  8   Basic
2012-03-01  13  Basic
2012-03-02  14  Reset
2012-03-02  12  Advanced
2012-03-02  12  Hang Up
2012-03-02  24  Reset
2012-03-02  5   Basic

Table 3 is [Repeats] and looks like:

Repeat_d    ID  R_Interaction
2012-03-01  13  Reset
2012-03-01  8   Basic
2012-03-02  14  Reset
2012-03-02  12  Advanced
2012-03-02  24  Reset

What I need to be able to do is SUM the total calls from [Interactions] as a total per Interaction type and day and group them by Lead and Int_Date = Repeat_d

How I want the result to look:

DATE       Lead  Total_Interactions  Total_Repeats  Interaction
2012-03-01    1                   1              0  Hang Up
2012-03-01    1                   2              1  Basic
2012-03-01    2                   1              1  Reset
2012-03-01    2                   1              0  Basic
2012-03-02    1                   1              1  Advanced
2012-03-02    1                   1              0  Hang Up
2012-03-02    1                   1              0  Basic
2012-03-02    2                   2              1  Reset

My Query so far looks like:

DECLARE @StartDate smalldatetime, @EndDate smalldatetime, @TL_ID as smallint
SET @StartDate = '20120301'
SET @EndDate = '20120331'
SET @TL_ID = '2'
SELECT
DATEADD(dd, DATEDIFF(dd, 0, [Int_Date]),0) as [Int_Date]
,[Interaction]
,COUNT([Interaction]) as [Total_Repeats]
FROM [Interactions] (NOLOCK)
LEFT JOIN [user_table] (NOLOCK) ON [id] = [id]
WHERE [Int_Date] BETWEEN @StartDate AND @EndDate
AND [Lead] = @TL_ID
GROUP BY DATEADD(dd, DATEDIFF(dd, 0, [Int_Date]),0), [Interaction]
ORDER BY [Int_Date], [Total_Repeats] DESC

Any help would be much appreciated. Thank you!

  • 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-03T10:02:11+00:00Added an answer on June 3, 2026 at 10:02 am

    Try the following query:

    DECLARE
        @StartDate SMALLDATETIME,
        @EndDate SMALLDATETIME,
        @TL_ID SMALLINT
    
    SELECT
        @StartDate = '2012-03-01',
        @EndDate = '2012-03-31',
        @TL_ID = '2'
    
    SELECT
        DATEADD(DD, DATEDIFF(DD, 0, [Int_Date]), 0) AS [Int_Date],
        u.[Lead],
        i.[ID],
        COUNT(1) + COUNT(r.[ID]) AS [Total_Interactions],
        COUNT(r.[ID]) AS [Total_Repeats],
        i.[Interaction]
    FROM
        [Interactions] AS i WITH (NOLOCK)
    JOIN
        [User_Table] AS u WITH (NOLOCK)
    ON
        u.[ID] = i.[ID]
    LEFT OUTER JOIN
        [Repeats] AS r WITH (NOLOCK)
    ON
        r.[ID] = i.[ID]
    AND r.[Repeat_d] = i.[Int_Date]
    AND r.[R_Interaction] = i.[Interaction]
    WHERE
        i.[Int_Date] BETWEEN @StartDate AND @EndDate
    AND u.[Lead] = @TL_ID
    GROUP BY
        DATEADD(DD, DATEDIFF(DD, 0, [Int_Date]), 0),
        u.[Lead],
        i.[ID],
        i.[Interaction]
    ORDER BY
        [Int_Date],
        u.[Lead],
        i.[ID],
        [Total_Repeats] DESC
    

    See it in action here: https://data.stackexchange.com/stackoverflow/query/68935/joining-3-tables-on-multiple-fields-sql-server

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

Sidebar

Related Questions

I am trying to insert certain values into the table using SQL server 2005.
I'm using SQL Server 2005 and I'm trying to achieve something like this: I
I'm using SQL Server 2005 Analysis Services and I'm trying to calculate distance inside
I am trying to learn SQL query optimization using SQL Server 2005. However, I
I'm trying to configure replication on SQL Server 2005. I can do it using
I am using SQL Server 2008 & 2005 (Express). I'm trying to extract part
[using SQL Server 2005] I have a table full of users, I want to
Using SQL Server 2005, I am trying to select a certain number of records
I am using SQL SERVER 2005. I have a table table1(ID,col1,col2,col3,col4); Now I have
Using SQL Server 2005 and Visual Studio 2005, I'm trying to create a SSIS

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.