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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:52:32+00:00 2026-05-23T08:52:32+00:00

I have a table (tbl_MatterItem) in my DB that tracks the dates that items

  • 0

I have a table (tbl_MatterItem) in my DB that tracks the dates that items are sent and received. If it hasn’t been sent or received, the value is NULL. I have another table (tbl_Matter) that I am linking to, to get the BillingLawyer for that particular item.

BillingLawyer     ItemSent     ItemReceived
-------------     --------     ------------
   Alison         09/09/09        NULL
   Alison         10/10/10        NULL
   Alison         11/11/11       13/11/11
   Alison         12/12/12        NULL

I would like to retrieve one row for each lawyer with their name, the number of items sent, and the number of items received.

BillingLawyer    Sent    Received
-------------    -----   --------
   Alison         4         1

Below is what I have so far:

SELECT BillingLawyer, 
(SELECT COUNT(DISTINCT itemSent)FROM tbl_matteritem mit WHERE itemid=2 AND itemSent IS NOT NULL AND mit.ItemSent= mi.itemSent) AS [Sent], 
(SELECT COUNT(DISTINCT itemReceived)FROM tbl_matteritem mitm WHERE itemid=2 AND itemReceived IS NOT NULL AND mitm.itemreceived = mi.itemreceived)AS Received
FROM tbl_matteritem mi JOIN tbl_matter m ON mi.matterid = m.matterid
GROUP BY BillingLawyer, ItemSent, itemreceived
ORDER BY 1

However my results show with an extra record and what appears to be bit values?:

BillingLawyer    Sent    Received
-------------    ----    --------
   Alison         0         0
   Alison         1         1
   Alison         1         0
   Alison         1         0
   Alison         1         0

Any ideas where I am going wrong?

  • 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-23T08:52:33+00:00Added an answer on May 23, 2026 at 8:52 am

    Try this:

    SELECT
        BillingLawyer,
        SUM(CASE WHEN ItemSent IS NOT NULL THEN 1 ELSE 0 END) AS Sent,
        SUM(CASE WHEN ItemReceived IS NOT NULL THEN 1 ELSE 0 END) AS Received
    FROM
        tbl_matteritem mi
    JOIN tbl_matter m ON
        mi.matterid = m.matterid
    GROUP BY BillingLawyer
    ORDER BY BillingLawyer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains intervals: CREATE TABLE tbl ( user_id: INTEGER, start:
I have a table on a server A and the same table on another
I have a table tbl_sky that has 2 properties name and model and I
In SqlServer 2005 I have a table with a TimeOfDay field that is a
I have the below Declare @tbl Table(Id int identity, SomeCol varchar(10) not null) Begin
I am using SQL Server 2008. I have a table (TBL_FILE) that stores user
I have a process that bulk inserts into a table from a CSV. I
i am doing a library project for my college. in that, i have table
I have the following table: CREATE TABLE [dbo].[omgbbq]( [tbl_key] [int] IDENTITY(1,1) NOT NULL, [name]
i have a table (tbl_world) which look like this id | first_name | last_name

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.