0

SQL is not really my strong point, so please excuse my ignorance.

This query returns all records which contain null values

;WITH XMLNAMESPACES('http://www.w3.org/2001/XMLSchema-instance' as ns)
SELECT *
FROM   Analytics
WHERE  (SELECT Analytics.*
        FOR xml path('row'), elements xsinil, type
        ).value('count(//*[local-name() != "colToIgnore"]/@ns:nil)', 'int') > 0

Source: Find All Rows With Null Value(s) in Any Column

The above query returns a list of records which have null values. How do I modify this query to return records which contains both null or empty columns.

Community
  • 1
  • 1
Navyseal
  • 891
  • 1
  • 13
  • 36

1 Answers1

0

You can try the following

;WITH XMLNAMESPACES('http://www.w3.org/2001/XMLSchema-instance' as ns)
SELECT *
FROM   Analytics
WHERE  (SELECT Analytics.*
        FOR xml path('row'), elements xsinil, type
        ).value('count(//*[local-name() != "colToIgnore"]/@ns:nil)', 'int') > 0
        OR
        (SELECT Analytics.*
        FOR xml path('row'), elements xsinil, type
        ).value('count(//*[text()=""])', 'int') > 0
Kiran Hegde
  • 3,651
  • 1
  • 16
  • 14