Skip to content
Advertisement

DB2: I want to see € or $ in the output of select

This simple query satisfy me

db2 => SELECT city,SUM(sales) as sum from offices group by city;

CITY                                                                                                SUM                              
---------------------------------------------------------------------------------------------------- ---------------------------------
Rome                                                                                                                        14000,
Paris                                                                                                                         19000,

But..how to add the $ or € symbol? To get an output like this?

CITY                                                                                                SUM                              
---------------------------------------------------------------------------------------------------- ---------------------------------
Rome                                                                                                                        14000$
Paris                                                                                                                         19000$

Advertisement

Answer

Normally, this kind of formatting is left to the client to display.

If you really need to have the DB do it, then VARCHAR_FORMAT is likely a better choice.

select city
   , varchar_format(sum(sales),'$999G999G990D99' as sales 
from offices group by city;

The G and D characters represent the grouping and decimal character for your locale

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement