Saman Gholami
Saman Gholami

Reputation: 3512

Remove Decimal Separator from Money

I have this query :

SELECT CONVERT(varchar, CAST(987654321 AS money), 1)

Now the result is :

987,654,321.00

But i want to get :

987,654,321

I want to do this in my query, what should i do?

Upvotes: 2

Views: 1758

Answers (2)

Dan Guzman
Dan Guzman

Reputation: 46203

The SQL Server money data type does not have decimal separators. It is a binary structure in the database. It seems you may want to convert a money data type to an integer in T-SQL and add separators. In that case try:

SELECT REPLACE(CONVERT(varchar, CAST(987654321 AS money), 1), '.00', '');

Upvotes: 1

bencripps
bencripps

Reputation: 2053

I would definitely not do this, but this will work if you absolutely need it:

DECLARE @value varchar(50)

SET @value = CONVERT(varchar(50), CAST(987654321 AS money), 1)
SELECT  LEFT(@value, len(@value) - 3)

this will return 987,654,321

Upvotes: 1

Related Questions