sgrgmngt
sgrgmngt

Reputation: 917

Coalesce Function in DB2

I am using IBM DB2. I have a query which gives the output as:

NAME / AMOUNT

CST / -

VAT / 1400

ST / -

I am trying to write a coalesce function for AMOUNT. The datatype of AMOUNT is decimal(10,2)

COALESCE(AMOUNT,'&nbsp')

The purpose of me doing is, I want a space if the AMOUNT is null, but all I get is an error like "incompatible argument".

How can I achieve a space? Please help!

Upvotes: 1

Views: 14080

Answers (1)

Sparky
Sparky

Reputation: 15095

The problem is you are saying this...

If amount is not NULL, display a decimal value, but if it is, display a character value instead. Try this

COALESCE(CAST(AMOUNT as VARCHAR(20)),' ')

Should solve your problem

Upvotes: 4

Related Questions