0
uid     external
rn345   --
ev456   --  
--      Peter

So I have the above table and I want to select the uid however I also wanted to substitute the value on the "external" field to the "uid" field if the value is blank. So essentially, I would get the following:

UID
rn345
ev456
Peter

Is this possible?

ubay25
  • 23
  • 7

1 Answers1

0

You need to use coalesce, which returns the second value if the first one is null:

select  coalesce(uid, external)
from    yourTable

Edit

If the uid field is blank instead of null, you'll have to use a case statement instead

select  case when uid is null or uid = '' then external else uid end
from    yourTable
Stefano Zanini
  • 5,876
  • 2
  • 13
  • 33