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)
 Find which atrributes are null in a row

Author  Topic 

memento
Starting Member

16 Posts

Posted - 2006-06-09 : 11:19:48
I was wondering if any of you knows of a simple way to select the name of the columns that have null values in a row of a table.

X002548
Not Just a Number

15586 Posts

Posted - 2006-06-09 : 11:29:30
[code]
SELECT *
FROM information_schema.Columns
WHERE IS_NULLABLE = 'YES'

[/code]

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

memento
Starting Member

16 Posts

Posted - 2006-06-09 : 14:05:10
Doesn't that return the columns that can hold null values, ie that don't have NOT NULL ?

What I'm trying to find is, in a record, what attributes are null (in that particular moment).
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-06-09 : 14:22:46
OH, you mean like each row that has null values?

Would you supply some sample information.

Read the hint link in my sig and post what it asks for



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-06-09 : 14:30:41
quote:
Originally posted by memento

Doesn't that return the columns that can hold null values, ie that don't have NOT NULL ?

What I'm trying to find is, in a record, what attributes are null (in that particular moment).


select column_name
from my_table
where column_name is null


CODO ERGO SUM
Go to Top of Page

memento
Starting Member

16 Posts

Posted - 2006-06-09 : 14:42:30
For instance

id |Name| Car nr | Boat nr | plane nr

1 Joe 23 null null
2 Jane null 1 22


I want to have a select that finds what transports Joe doesn't have, so in this case it would return "boat nr" and "plane nr".

In the general solution, I want to find what transports people don't have at that time.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-06-09 : 17:36:36
[code]
select
Name,
[Null transport] = 'Boat nr'
from
my_table
where
[Boat nr] is null
union all
select
Name,
[Null transport] = 'plane nr'
from
my_table
where
[plane nr] is null
[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -