Count number of NULL values in each column in SQL

前端 未结 4 402
Happy的楠姐
Happy的楠姐 2020-12-10 08:07

I am trying to write a script that will show the number of non-null values in each column as well as the total number of rows in the table.

I have found a couple wa

4条回答
  •  生来不讨喜
    2020-12-10 08:10

    you can go with dynamic sql and sys tables.
    depending on the version of sql you are using the syntax will change slightly but these are the steps:
    - list the columns reading sys.columns and save the list in a temp table or table variable
    - make a loop through that temp table and build the sql using the same logic you would apply manually
    - execute the dynamic sql built on previous step with sp_executesql

提交回复
热议问题