dynamic column name

Posted on 2005-03-07
Medium Priority
Last Modified: 2012-06-27
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)
where co.TABNAME = 'MYTABLE'
order by co.COLNO


Question by:fho
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 18

Accepted Solution

BigSchmuh earned 2000 total points
ID: 13490107
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
  SELECT Concat('SELECT Count(*) FROM ',Concat(co.TABNAME,';'))
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


Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question