Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL replace dot with comma

I have following code:

SELECT cast(Listenpreis*1.19 as decimal(29,2)) as Listenpreis
 FROM [SL_M03KNE].[dbo].[ARKALK]

I get this value: 5.59

I try to replace the dot to a komma so i get the Value: 5,59

I try the code:

SELECT replace((cast(Listenpreis*1.19 as decimal(29,2)) as Listenpreis),'.','))
 FROM [SL_M03KNE].[dbo].[ARKALK]

But something is wrong with the Syntax. Any Ideas?

I found out: if I do a

select Artikelnummer,Listenpreis*1.19 as money from [SL_M03KNE].[dbo].[ARKALK]

i get: 5,59

If i do a

EXEC master..xp_cmdshell 'bcp "select Artikelnummer,Listenpreis*1.19 as money from [SL_M03KNE].[dbo].[ARKALK]" queryout "D:\shop\xml\Artikelpreise_ohne.csv" -E -c -T -x

the bcp do a conversion from the komma to dot. How can i fixed this?

like image 515
user2675045 Avatar asked Aug 15 '13 11:08

user2675045


2 Answers

Your as Listenpreis aliasing is in the wrong place. It needs to be the last thing. Also the '.',' part.

SELECT REPLACE(CAST(Listenpreis*1.19 AS DECIMAL(29,2)) ,'.',',')  AS Listenpreis
 FROM [SL_M03KNE].[dbo].[ARKALK]

SQLFiddle DEMO

like image 141
Nenad Zivkovic Avatar answered Sep 24 '22 16:09

Nenad Zivkovic


This should work:

select replace(cast(Listenpreis*1.19 as decimal(29,2)),'.',',') as Listenpreis
 from [SL_M03KNE].[dbo].[ARKALK]

It does sound like you're compensating for cultural settings, have a look at the COLLATE statement.

like image 33
Chris Avatar answered Sep 22 '22 16:09

Chris