Dynamic SQL Query to ignore null values based on null value in cell

前端 未结 3 1463
一向
一向 2021-01-28 05:10

I have a dynamic SQL query with different column names and tables at runtime.

I am looking to get the SQL query to ignore reading data based on if a row contains Null v

3条回答
  •  忘了有多久
    2021-01-28 05:57

    No, there's no select where * is not null-type query. You have to test every field individually:

    SELECT ...
    FROM ...
    WHERE field1 is not null AND field2 is not null AND .... AND fieldN is not null
    

    You could try a COALESCE() operation, perhaps, but that's still ugly:

    WHERE COALESCE(field1, field2, ..., fieldN, 'allarenull') <> 'allarenull'
    

    but then you STILL have to list all of the fields in the table.

提交回复
热议问题