Issue With Coalesce


Issue With Coalesce


Currently, I am having issue with Coalesce statement.

I have 2 columns, a & b with datatype in database.

While querying, I want to create a column; c
Which is having value of a; if a is not having any value (is empty), need to use b;
& if b is not having any value (is empty), need to leave it empty.

Ex: 2 input cols with char(12) datatype
row a b
1 9/22/2009 9/12/2009
3 9/24/2009
4 8/20/2007

I want the output as:

row c
1 9/22/2009
3 9/24/2009
4 8/20/2007

The Coalesce statement is taking only value of col a....if its empty, leaving the output empty.
The below statements didn't worked:

Coalesce(a, b, ' ') As c;

Coalesce(CAST(a As char(12)), CAST(b As char(12)), ' ') As c;

Please help me on this. Thanks

Re: Issue With Coalesce

is the value in Column a is NULL or empty string, COALESCE works for NULL values, change empty string to NULL with the help of NULLIF