how to get rows with a blank value in a column

Database
Enthusiast

how to get rows with a blank value in a column

I have a data that has customer information. This data is set up by the IT people, and I am merely a user of that data. I want to get all the customers that the SSN is blank. If you print the data out for these customers, you would see that the SSN is blank, or there is nothing on the paper. (In Teradata term, it might be called blank, empty, null, etc, and I am not sure). Can you please tell me how to do it?

The code below is what I use, but I am not sure, can you please take a look, and give me the correct code if mine is wrong:

/*code start*/

SELECT *

FROM TABLE

WHERE SSN =' ' /*There is only one space here, do I need more spaces?*/

or SSN is NULL

ORDER BY SSN

/*code end*/

Thanks

Yunfei

5 REPLIES
Enthusiast

Re: how to get rows with a blank value in a column

Hi,

Your sql query is correct.  In (IS NULL) keyword space should be removed and it should be ISNULL .  I think one space is enough...

Teradata Employee

Re: how to get rows with a blank value in a column

You can use something like below:

SELECT *

FROM TABLE

WHERE TRIM(SSN) = '' OR SSN IS NULL

Teradata Employee

Re: how to get rows with a blank value in a column

Also .... Empty string i.e. '' .... is not as same as NULL .... NULL represents absence of any value whereas empty string is a value itself.

HTH!

Enthusiast

Re: how to get rows with a blank value in a column

1 ques?

I have output from a SQL as below:

COL1     COL2   COL3

NULL     NULL     ABC

NULL     NULL     NULL

DEF       NULL     NULL

and 1 want output as below:

COL1     COL2     COL3

DEF                     ABC

Any help?

Enthusiast

Re: how to get rows with a blank value in a column

Hi,

You have to use coalesce function to get the result.

Saravanan