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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:06:25+00:00 2026-05-23T02:06:25+00:00

I am currently using this SQL statement to return a count by who completed

  • 0

I am currently using this SQL statement to return a count by who completed each record (RFI):

SELECT Completed_By, COUNT(DISTINCT Unique_ID) AS RFICount FROM RFI_ 
WHERE Date_Submitted BETWEEN '20110101' AND '20110630' 
GROUP BY Completed_By

This returns a data set like the following:

Completed_By     RFICount
------------     ---------
SMITH, Bob       1
DOE, John        15
WARNER, Jack     11

This is how I want it to look. However, someone can be the primary or secondary person who completed or assisted in the completion of a record (RFI). I want to show this all in one column, regardless of whether they completed the record (Completed_By) or assisted with it (Assisting_Analyst).

When I use the following SQL statement, it shows these as separate when they need to be aggregated:

SELECT Completed_By, Assisting_Analyst, COUNT(DISTINCT Unique_ID) AS RFICount 
FROM RFI_ WHERE Date_Submitted BETWEEN '20110101' AND '20110630' 
GROUP BY Completed_By, Assisting_Analyst

This returns the following type of output:

Completed_By     Assisting_Analyst     RFICount
------------     -----------------     --------
SMITH, Bob       NULL                  1
DOE, John        NULL                  15
WARNER, Jack     NULL                  7
WARNER, Jack     SMITH, Bob            4

Since Bob Smith assisted Jack Warner with four records (RFIs), there is a separate row created. But I simply want each to get individual credit and have it show up in one column, like so:

Completed_By     RFICount
------------     ---------
SMITH, Bob       5
DOE, John        15
WARNER, Jack     11

In the above example, the four records they worked on jointly are credited to both of them. Granted, this means some records are being counted twice, but that is what I want for this application.

I have tried UNIONS and a bunch of other stuff but it either doesn’t give me what I want as I want it displayed or it gives me an error with no data. I know DISTINCT has got to go, but not sure how to do this exactly. This is being done in SQL Server 2008 R2. Help?

  • 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-05-23T02:06:25+00:00Added an answer on May 23, 2026 at 2:06 am
    SELECT t.Completed_By, COUNT(DISTINCT t.Unique_ID) AS RFICount 
        FROM (SELECT Completed_By, Unique_ID
                  FROM RFI_ 
                  WHERE Date_Submitted BETWEEN '20110101' AND '20110630' 
              UNION ALL
              SELECT Assisting_Analyst AS Completed_By, Unique_ID
                  FROM RFI_ 
                  WHERE Date_Submitted BETWEEN '20110101' AND '20110630'
                      AND Assisting_Analyst IS NOT NULL) t
        GROUP BY t.Completed_By
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this query: return from oi in NHibernateSession.Current.Query<BlaInteraction>() select new BlaViewModel {
I'm currently using this jQuery validate plugin and having an issue in IE where
I'm currently using this method in calling batch files in vb.net: Private Sub Button3_Click(ByVal
I'm currently using this code to calculate the sunrise / sunset times. (To be
I am a rank beginner in C#. I am currently using this code: objGraphics.Clear(SystemColors.Control);
I'm currently using DPack as this adds a Collapse All Projects option to the
I am currently using code similar to this: try { // IE ONLY var
I'm currently using Entity Framework and am running into this issue: The relationship between
I'm currently using jQuery to make a div clickable and in this div I
Currently, I am using this query, which does a pretty good job of finding

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.