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

后端 未结 3 1823
梦毁少年i
梦毁少年i 2020-12-06 00:16

I\'m trying to create a query that will return all the rows that have a null value across all but 1 column. Some rows will have more than one null entry somewhere. There i

3条回答
  •  温柔的废话
    2020-12-06 01:02

    In SQL Server you can borrow the idea from this answer

    ;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
    

    SQL Fiddle

    Likely constructing a query with 67 columns will be more efficient but it saves some typing or need for dynamic SQL to generate it.

提交回复
热议问题