jmasterx
jmasterx

Reputation: 54113

Return empty string if string is 0 in SQL

What could I do if, say I do this:

SELECT name as "cname" from dba

But if the value of name is '0' I want cname to be = to an empty "" string.

What could I use, in standard sql to do this.

Thanks

Upvotes: 1

Views: 1493

Answers (3)

Holger Brandt
Holger Brandt

Reputation: 4354

Use a case statement:

SELECT CASE name WHEN '0' THEN '' ELSE name END AS cname from dba

Upvotes: 3

Alex K.
Alex K.

Reputation: 175766

You could use a CASE;

SELECT 
  case name when '0' then '' else name end as "cname" 
from dba

Upvotes: 5

csm8118
csm8118

Reputation: 1213

Use a case statement:

SELECT CASE WHEN name='0' THEN '' ELSE name END AS cname FROM dba

Upvotes: 2

Related Questions