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
 General SQL Server Forums
 New to SQL Server Programming
 Return only columns that are not null

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-20 : 08:22:00
johnny writes "I am trying to return only the columns from multiple tables that are NOT NULL for a specific ID. Once I have the tables JOINED is there a way to only get those columns that are populated. Thanks."

karuna
Aged Yak Warrior

582 Posts

Posted - 2006-02-20 : 08:53:01
Is this what you are looking for?
select col1,col2 from tbl1 where col1 is not null

Thanks

Karunakaran
Go to Top of Page

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2006-02-20 : 09:06:28
It sounds like you want specific columns, with inner join. Please give more detail about your requirements re: output (columns) and table structure (foreign keys etc.)

Sounds like you need:

Select
table1.Column1,
table2.Column2
from
Table1
inner join
table2
on table.pk = table2.fk
--this ensures you only get rows from table 1 that have a match in table2
where
table1.id = @SpecificId --this ensure you have the rows for your specifi id.


If you are trying to get only not null coums from all the tables, after you do you joins, then you have to (a) re-look at your requirements and ensure that is what you want, (b) look at using ISNULL and/or coalesce or possible CASE, but without more detail on the table strucutre and requirements, this is largely guessing...


*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page
   

- Advertisement -