Link to home
Start Free TrialLog in
Avatar of jfreeman2010
jfreeman2010Flag for United States of America

asked on

t-sql coalesce problem with space in column value

t-sql coalesce problem with space in column value

I have a SQL select statement using coalesce as following

SELECT  COALESCE (A.FIRST_NAME, B.FIRST_NAME) AS FIRST_NAME,
      COALESCE (A.LAST_NAME, B.LAST_NAME) AS LAST_NAME
FROM TEST_A A
 INNER JOIN TEST_B B
 ON A.ID = B.ID

It works as long as the A table column if is null, it shows the b table data.  
My problem is table A has value of '' (space, not null value).

What can I do to fix this?
ASKER CERTIFIED SOLUTION
Avatar of JestersGrind
JestersGrind
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jfreeman2010

ASKER

Thank you for the response.  try the nullif, did not work.

What I am looking is if A.last_name is null or space or '', return value from  b.last_name.

thanks,
thanks!!!