This:
SELECT 'R$ '+convert(varchar(50), CAST(998547 as money), -1) MONEYVALUE
Will output: R$ 998,547.00
In Brazil the right is: R$ 998.547,00
How can I output the right format?
You need to use the currency format using a selected culture by parameter for SQL Server 2012.
Like this:
select
'R$ ' + CONVERT(varchar(50), cast(MONEYVAL as MONEY), -1) MONEYVALUE -- Custom Format
, FORMAT(MONEYVAL, 'C', 'en-us') USA
, FORMAT(MONEYVAL, 'C', 'pt-br') Brazil
from ACCOUNT;
Look for currency format at the official site
You can see the example at the SQL Fiddle
For Sever 2008 R2 dosen't have a native function to format currency, but you could download some library like this or write your own format function or simple just use replace to make it easy but not so fency.
SELECT
'R$ ' + convert(varchar(50), CAST(moneyVal as money), -1) MONEYVALUE,
'RS ' + REPLACE(REPLACE(REPLACE(CONVERT(varchar(50), (CAST(moneyVal AS money)), -1), ',', ';'), '.', ','), ';', '.')
from Account
998547.00
, then do the formatting in your client-side code. the db should never have to worry about who's sitting at the keyboard and what their national format is.FORMAT
isn't an option in sql-server-2008-r2