I would like to create dynamic sql query where for the set of tables and fields from information schema I will count null and non-null values of these fields.
I have idea to use it something like this (if I am not mistaking)
select distinct DB_NAME() as db_n,
TABLE_NAME,
COLUMN_NAME,
DATA_TYPE as DataType
into #baseNew
from INFORMATION_SCHEMA.COLUMNS
where left(COLUMN_NAME,4) ='new_'
order by TABLE_NAME,COLUMN_NAME
this next part that should be dynamic would be something like this
select distinct b.db_n,
TABLE_NAME,
COLUMN_NAME,
(select case when column_name is null then 1 else 0 end as NullValues
from table_name) NullValues,
(select case when column_name is not null then 1 else 0 end as NotNullValues,
from table_name) NotNullValues,
(select count(1) as numRows from table_name) TotalRows
from #baseNew b
(and probably insert in some table or data frame for python)
And if that is possible to be run in python script to be run on multiple DBs