Coyolero
Coyolero

Reputation: 2433

How do I convert a Decimal to Varchar with a specific format

I'm using SQL Server 2008

I have just a decimal value as 137909.19 and I need to convert it to varchar with this format: 137,909.19.

declare @myNumber decimal(15,2) = 137909.19

select CAST(@myNumber AS varchar(20)) -- Result: 137909.19

I have looked over several posts but I can't found the solution.

How could I achieve this?

Upvotes: 1

Views: 11227

Answers (2)

comfortablydrei
comfortablydrei

Reputation: 316

SELECT FORMAT(@myNumber,'N2', 'en-US') 

Upvotes: 0

robgfaulkner
robgfaulkner

Reputation: 106

Try casting it as money.

declare @myNumber decimal(15,2) = 137909.19 
declare @myvalue varchar(20)

set @myvalue = convert(varchar, cast(@myNumber as money),1) 
PRINT @myvalue

output will be "137,909.19"

Upvotes: 7

Related Questions