Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Skip columns with only null values.

Author  Topic 

Gingis
Starting Member

6 Posts

Posted - 2002-04-10 : 18:09:15
Hello,

I try to skip nulls columns in my select statement.
My table looks like that :

Firstname varchar(50)
Lastname varchar(50)
Comments1 varchar(50)
Comments2 varchar(50)
Comments3 varchar(50)

I would like to only select the columns which have at least one non-null value. If all of the n lines have a null value for the Comments3 field, I don't want to use this columns in my query.

The query would looks like that : select <every non-nulls columns> from mytable. You see what I mean ?

Of course I can make test (if) and build a dynamic query but I'd rather use a single query.

Thanks for your help;

Gingis.

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-04-10 : 20:27:20
OK, a starting SELECT statement would look like
SELECT Firstname, Lastname, Comments1, Comments2, Comments3 FROM MyTable.

Now, are you saying that if EVERY row that will be returned has (for example) only nulls in Comments2, then that entire column should be dynamically removed from the SELECT statement? OR Are you saying that each row should somehow magically remove the null fields and then rearrange the data?

Either way, it sounds like what you are trying to do is really a presentation issue, and not a database issue, and should be handled by whatever process receives the recordset that this select statement returns. So what ARE you trying to do anyway?

------------------------
GENERAL-ly speaking...
Go to Top of Page
   

- Advertisement -