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
 Comma Sperated amount

Author  Topic 

velliraj
Yak Posting Veteran

59 Posts

Posted - 2010-08-06 : 05:54:42
Hi,

I have the value which i was not able to convert into money due its
data range is more than 8bytes.
But i can able to convert into decimal, but i need in the money format like comma separated amount

select convert(varchar(100),convert(money,1235353536586647567.00),1)
select convert(varchar(100),convert(decimal32,2),1235353536586647567.00),1)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-06 : 06:30:35
What you are talking about is the GRAPHICAL representation of the money value. It has NOTHING to do with it's value.
It's a presentation issue.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Devart
Posting Yak Master

102 Posts

Posted - 2010-08-06 : 06:34:22
Hello,

For example:

select replace(convert(varchar(100),convert(decimal(32,2),1235353536586647567.00),1),'.',',');

Best regards,

Devart,
SQL Server Tools:
dbForge Schema Compare
dbForge Data Compare
dbForge Query Builder
Go to Top of Page

velliraj
Yak Posting Veteran

59 Posts

Posted - 2010-08-06 : 06:37:30
Sorry deva,

I need the result set in this format
12,353,535.00
above format i was not able to get if i use the decimal conversion.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-06 : 07:47:13
[code]CREATE FUNCTION dbo.fnDoMyPresentationFormatting
(
@Value DECIMAL(32, 2)
)
RETURNS VARCHAR(50)
AS
BEGIN
DECLARE @s VARCHAR(50),
@ptr SMALLINT

SELECT @s = CAST(@Value AS VARCHAR(50)),
@ptr = DATALENGTH(@s) - 5

WHILE @ptr >= 1
SELECT @s = STUFF(@s, @ptr, 0, ','),
@ptr = @ptr - 3

RETURN @s
END
GO

DECLARE @Value DECIMAL(32, 2) = 1235353536586647567
SELECT dbo.fnDoMyPresentationFormatting(@Value)
GO[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -