Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concat an integer value with a string in DB2 procedure

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.

like image 684
user987880 Avatar asked Dec 27 '22 12:12

user987880


2 Answers

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
like image 174
MrG Avatar answered Jan 04 '23 22:01

MrG


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

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

OR

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

like image 42
Brian Avatar answered Jan 05 '23 00:01

Brian