Chris
Chris

Reputation: 3129

If column data is null or contains an empty string then 'N/A'

I have a column called County, and in this column sometimes there is a county and other times its either empty or contains NULL. So far I am able to change it when there is an empty string to N/A, but not sure how to change it if there is a NULL as well. So far I am using a case statement to check if the column contains an empty string

case County when '' then 'N/A' end

but I need to check if the column data is NULL as well and change it to N/A.

So in short, if any data in the County column is an empty string or is NULL then I need to add N/A.

Upvotes: 0

Views: 3757

Answers (3)

juergen d
juergen d

Reputation: 204884

case when County = '' or County is null
     then 'N/A' 
     else County 
end

Upvotes: 1

Martin Smith
Martin Smith

Reputation: 453648

One way would be

Case when County <>  '' then  County ELSE 'N/A' end

Both nulls and empty strings end up at the else.

Upvotes: 3

randcd
randcd

Reputation: 2293

SELECT ISNULL(NULLIF(LTRIM(RTRIM(County)),''), 'N/A') County

Upvotes: 2

Related Questions