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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Comma Sperated amount
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

velliraj
Yak Posting Veteran

India
59 Posts

Posted - 08/06/2010 :  05:54:42  Show Profile  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/06/2010 :  06:30:35  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 08/06/2010 :  06:34:22  Show Profile  Visit Devart's Homepage  Reply with Quote
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

India
59 Posts

Posted - 08/06/2010 :  06:37:30  Show Profile  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/06/2010 :  07:47:13  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000