Home > database >  cast numbers and decimals into INT
cast numbers and decimals into INT

Time:06-03

I have [funds] that have been presented in different formats, some are decimals, others numbers:

Null
0.00
0.55
55
55555555555

etc

I tried to use this: ,CAST (REPLACE ([funds],'.','') AS INT) AS [funds]

but got this mistake:

The conversion of the varchar value '288294130100' overflowed an int column.

How do I ned to treat the combo of numbers and decimals?

CodePudding user response:

You can cast them to BIGINT. But, when you cast to BIGINT, the decimal places will be lost.

SELECT cast(v as bigint) as bigvalue FROM (
VALUES
(Null)
,(0.00)
,(0.55)
,(55  )
,(55555555555)
,(288294130100)) as t(v)
bigvalue
NULL
0
0
55
55555555555
288294130100
  • Related