BIReportGuy
BIReportGuy

Reputation: 817

Tsql - How to Cast and Convert the same field

I have this value in a field +000000019900000000

The actual value that I need is 19.90.

How do I write a statement to convert and cast this all on the same line?

enter image description here

Upvotes: 0

Views: 94

Answers (2)

BIReportGuy
BIReportGuy

Reputation: 817

Here's another way to do this.

SELECT
'CLOSE PRICE'   = CAST(round(CLOSEPRICE,2)as decimal (30,2))
FROM TABLE

This is what I ended up using in my query.

Upvotes: 0

Kason
Kason

Reputation: 797

SELECT 
   CAST(LEFT(CLOSE_PRICE,10)
   +'.'
   +RIGHT(CLOSE_PRICE,LEN(CLOSE_PRICE)-10) AS DECIMAL(10,2))
FROM [testTable]

It would be fine. I tested the result is 19.90

Upvotes: 1

Related Questions