Query to display both null and value

Raj0125 511 Reputation points
2022-09-01T09:05:39.423+00:00

Hi,

I am trying to write Query having column called Ded_Amt to display having both NULL and value for partiuclar id.
please assist i need the query results as below.
If Ded_Amt having single value no need to display.
236865-image.png

Azure SQL Database
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 41,496 Reputation points
    2022-09-01T09:20:07.22+00:00

    If Ded_Amt having single value no need to display.

    Something like this; Id = 102 has only one value and isn't displayed

    ;WITH demoData AS  
        (SELECT 100 AS ID, NULL AS Ded_Amt  
         UNION ALL SELECT 100, 'USD'  
         UNION ALL SELECT 101, NULL  
         UNION ALL SELECT 101, 'GBP'  
         UNION ALL SELECT 102, 'EUR')  
        ,sub AS  
         (SELECT ID, COUNT(*) AS Cnt  
          FROM demoData  
          GROUP BY ID  
          HAVING COUNT(*) > 1)  
    SELECT *  
    FROM sub  
         INNER JOIN  
         demoData  
             ON sub.ID = demoData.ID  
    

0 additional answers

Sort by: Most helpful