CharlieShi
CharlieShi

Reputation: 916

How to convert 71632.0638353154 to 71,632.06 in SQL Server and SYBASE?

Here I have a question about data converting regarding SQL Server and SYBASE.

Take 71632.0638353154 as an example, how to convert it to 71,632.06 in SQL Server and SYBASE?

I know that there is a convert() function in SQL Server and SYBASE, but every time when I tried to use it to convert that number, the database UI will throw me an exception.

I use sybase UI to excute below SQL instance:

select convert(varchar(30),convert(varchar(8),convert(money,71632.0638353154),1))

but this causes this error:

Insufficient result space for explicit conversion of MONEY value '71,632.06' to a VARCHAR field.

Would anyone tell me how to do it? thx.

Upvotes: 0

Views: 4500

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

The more generic solution is:

select cast(71632.0638353154 as decimal(10, 2))

The cast function is standard SQL and available in most databases. DECIMAL is a built-in data type.

Upvotes: 0

Martin Smith
Martin Smith

Reputation: 453298

I'm unable to test in Sybase but

SELECT CONVERT(VARCHAR(30), CAST(71632.0638353154 AS MONEY),1)

works for me in SQL Server.

Upvotes: 1

Related Questions