Skip to content
Advertisement

Dynamic SQL :: Calculate percentage of NULLs per index

I have a query that help me list all index in a database and works pretty well:

Unfortunately if I uncomment the 6th line the word t.name is underlined in red and if I run the query I receive the error:

How can I make this subquery work?

The goal is to have a percentage of NULLs on each column

Advertisement

Answer

Your question and query are quite interesting and can be resolved with the help of statistics which always exist for columns participating in a index as is the case of the columns your are selecting in your query.

For accurate results, it is beneficial to update the statistics before running the query I’m providing below.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement