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: