5

I have a variable, price dec(5,0). How can I concat a static string "dollar" to that and save as a char(10)?

If the price is 55555, the result should be 55555 Dollar and this should be saved as a char(11).

How can I do it? I tried casting and just concat using '+', but it was not working.

2 Answers 2

9

The concat operator in DB2 is a double pipe, ||.

Also, you'll need to cast the decimal value to a char before you can concatenate.

Something like:

select cast(55555 as char(5)) || ' Dollar' from sysibm.sysdummy1
3

No casting is needed - both of the exampples below work:

CONCAT(55555, ' Dollar') as "Test Column"

OR

55555 || ' Dollar' AS "Test Column 2"

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.