0

I have values like this in my amount column

323547.23700
12345643.34222

I want to convert that in this format

$323,547.24
$12,345,643.34

I am using this

CHAR(36)+CONVERT(VARCHAR,@Amount,1)

but this is not giving me what I want

This might give a hint what I am doing

DECLARE @amount numeric(30,5)
SET @amount = 323547.23700
DECLARE @amount1 numeric(30,5)
SET @amount1 =12345643.34222

SELECT [USD Amount]= CHAR(36)+CONVERT(VARCHAR,@amount,1)
Zerotoinfinity
  • 6,290
  • 32
  • 130
  • 206

2 Answers2

1

As Ademar pointed out, you are missing the explicit length of the varchar column, this does the trick:

SELECT [USD Amount]= CHAR(36)+CONVERT(VARCHAR(30),@amount,1)

The 1 in the end should give you the desired decimal point and its values.

ntziolis
  • 10,091
  • 1
  • 34
  • 50
1

We can cast the @amount to money data type first. And then convert to varchar bt specifying the style as 1.

DECLARE @amount numeric(30,5) SET @amount = 323547.23700 DECLARE @amount1 numeric(30,5) SET @amount1 =12345643.34222

select CHAR(36)+CONVERT(varchar(20),CAST(@amount as money),1) select CHAR(36)+CONVERT(varchar(20),CAST(@amount1 as money),1)