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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:12:49+00:00 2026-06-15T17:12:49+00:00

I have a problem which i thought one of the questions would solve at

  • 0

I have a problem which i thought one of the questions would solve at the bottom but i still have a problem. The issue is my case statement is wrong (but runs without an error) but unsure what else i am missing.

My aim is, if DueDate IS NULL because there is no record in Table2 therefore all i want is for this value to be displayed as ‘No’ and not ‘NULL’. I added “IsNull” into my code but hasnt solved my problem. I have seen ISNULL() and COALEASE() on these forums but unable to get my desired result

Here is my working code below:

SELECT 
    Client, 
    COUNT(*) AS ReadyRecords, 
    (SELECT COUNT(*) FROM Table1 EPR WHERE actioned=8 AND EPR.Client=Table1.Client) AS Outstanding, 
    (SELECT TOP 1 
        CASE 
            WHEN DueDate < GETDATE() THEN 'Yes' 
            WHEN DueDate IS NULL THEN 'No' 
        ELSE 'No' 
        END AS DueDate
    FROM Table2 GL WHERE GL.Client=Table1.Client ORDER BY DueDate) AS DueDate

    FROM Table1 WHERE Actioned=2 GROUP BY Client

EDIT:

Current Result Set:

Client   | ReadyRecords  |  Outstanding  |  DueDate

Test     |     42        |      54       |   NULL
Stack    |     150       |      10       |   NULL
JBloggs  |     32        |      28       |   Yes
DBloggs  |     2         |      17       |   Yes
Overflow |     1         |      1        |   No

Desired Result Set:

Client   | ReadyRecords  |  Outstanding  |  DueDate

Test     |     42        |      54       |   No
Stack    |     150       |      10       |   No
JBloggs  |     32        |      28       |   Yes
DBloggs  |     2         |      17       |   Yes
Overflow |     1         |      1        |   No

Table 1:

id      |  Client   |   Actioned  | etc...

5245    |  Test     |      8      | etc...
....so on

Table 2:

id   |   Client   |   DueDate

1    |  JBloggs   | 2012-12-01 00:00:00.000
2    |  DBloggs   | 2012-12-05 00:00:00.000
3    |  Overflow  | 2012-12-12 00:00:00.000

Let me know if you need anything else.

Similar/Related Questions:

  • Using case in a sql select statement
  • T-SQL CASE Clause: How to specify WHEN NULL
  • 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-15T17:12:50+00:00Added an answer on June 15, 2026 at 5:12 pm

    You need to apply the ISNULL() or COALESCE() function to the whole inline subquery, like this:

    SELECT 
        Client, 
        COUNT(*) AS ReadyRecords, 
        (SELECT COUNT(*) FROM Table1 EPR 
         WHERE actioned=8 AND EPR.Client=Table1.Client
        ) AS Outstanding, 
    
        COALESCE(
            (SELECT TOP 1 
                CASE 
                    WHEN DueDate < GETDATE() THEN 'Yes' 
                END AS DueDate
            FROM Table2 GL WHERE GL.Client=Table1.Client ORDER BY DueDate
            ), 'No' 
        ) AS DueDate
    
    FROM Table1  WHERE Actioned=2  GROUP BY Client ;
    

    or move the CASE expression there:

    SELECT 
        Client, 
        COUNT(*) AS ReadyRecords, 
        (SELECT COUNT(*) FROM Table1 EPR 
         WHERE actioned=8 AND EPR.Client=Table1.Client
        ) AS Outstanding, 
    
        CASE WHEN 
               (SELECT TOP 1 
                  DueDate
                FROM Table2 GL WHERE GL.Client=Table1.Client ORDER BY DueDate
               ) < GETDATE() 
            THEN 'Yes'
            ELSE 'No'
        END AS DueDate
    
    FROM Table1  WHERE Actioned=2  GROUP BY Client ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem which I don't really know how to solve. I have
I have another weird problem which I have not been able to solve in
I have a small problem which i can't seem to solve myself. Look at
I actually have two questions regarding the same problem but I think it is
I have a design problem which I would like some input on. Here are
I have a problem which makes me crazy. I think it is very easy
I have a problem which requires a reversable 1:1 mapping of keys to values.
I have a problem which I cant seem to find answer to through searches
I have a problem which I don't know how to fix. It has to
I have a problem which i can't seem to find the solution to. I

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.