dynamic column name

Is it possible to build a SQL query in which the name of a column would be dynamic?

I need to create statistics about the content of tables.

Hereafter is an extract of the request. For each column of MYTABLE, I want to know how many rows have a NULL value.

select  co.TABNAME,  co.COLNAME, (select count(*) from SQLDBA.MYTABLE where co.COLNAME is NULL)
from SYSCAT.COLUMNS co
where co.TABNAME = 'MYTABLE'
order by co.COLNO

Thanks

Fred
LVL 1
fhoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BigSchmuhCommented:
I think you can do it 3 ways:
1/ Use the standard statistics
as they perfectly answer your how many nulls question

2/ Use a SQL query which returns a SQL query
Example:
  SELECT Concat('SELECT Count(*) FROM ',Concat(co.TABNAME,';'))
  FROM SYSCAT.COLUMNS co
put the results in a batch and run it logging to a txt file (you'll found it easier than everything else)

3/ Use C and APIs
Perfect results guaranteed but it's a lot of work

hth
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.