Michael Jaynes
Michael Jaynes

Reputation: 23

Add a negative symbol to a numeric value

Using SQL 2014 I need to append a negative sign to a list of numeric values. The data are dollar amounts with numerous places behind the decimal point. I did convert the data to numeric(15, 2)

Here is my select statement.

SELECT '-' + convert(15,2), MONEY from TABLE

I am getting the error: Arithmetic overflow error converting varchar to data type numeric.

I tried converting to varchar as well.

select '-' + CONVERT(varchar10), (convert(numeric(15, 2), MONEY)) from
TABLE

I get the same error as above. Any ideas how to accomplish this?

Upvotes: 1

Views: 3160

Answers (3)

Hadi
Hadi

Reputation: 37338

why not trying Cast Function

SELECT -1 * CAST(MONEY  as Numeric(15.2)) from TABLE

Upvotes: 0

David דודו Markovitz
David דודו Markovitz

Reputation: 44961

SELECT -convert(MONEY, 15.2) from TABLE

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270311

How about multiplying by -1 instead? Something like this:

SELECT -1 * convert(MONEY, 15.2) from TABLE

Your syntax isn't correct. I am guessing you want something like the above.

Or subtract from 0.

Upvotes: 1

Related Questions