Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Decimal Datatype with Commas

Author  Topic 

user45
Starting Member

10 Posts

Posted - 2011-11-22 : 04:30:55
Hi I am trying to create a select statement where I want my results to contain a currency symbol (€), rounded to the nearest euro and contains commas

Query 1:
SELECT '€' + CONVERT(varchar(10), CONVERT(money, SUM(Total)),1) as 'Total' FROM a
Result: €46,533.05

Query 2:
SELECT '€' + CONVERT(varchar(10), CONVERT(decimal, SUM(Total)),1) as 'Total' FROM a
Result: €46533

So basically I want the result to be in the format of €46,533

Is there an easy way to do this?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-22 : 04:32:17
yes. At your front end application. It is much easier to do it than in SQL Server


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

user45
Starting Member

10 Posts

Posted - 2011-11-22 : 04:35:28
If I use Query 2 above and use my front end application to do this it displays the output as €46,533.00.
So I need a way to do it in SQL Server. Is it very complicated to do?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-22 : 04:42:07
quote:
Originally posted by user45

If I use Query 2 above and use my front end application to do this it displays the output as €46,533.00.
So I need a way to do it in SQL Server. Is it very complicated to do?


its really ugly to do this in sql server as it involves unnecessary casting to varchar format which will make manipulations like sorting difficult .
Most front end tools have functions readily available for generating this format so thats why its always recommended to do it there and not in sql.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

user45
Starting Member

10 Posts

Posted - 2011-11-22 : 04:47:09
hmmm I thought as much
Thanks for your help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-22 : 05:11:39
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -