Nested CAST not working

Why does nested MySQL not work in MySQL? (It uses SQL Server)

select cast(cast(myColumn as decimal(5,2)) as int) from myTable 

SQLFiddle example

+6
casting mysql nested
source share
2 answers

According to the manual :

CAST(expr AS type) [...]

CONVERT(expr,type) [...]

type can be one of the following values:

  • BINARY[(N)]

  • CHAR[(N)]

  • DATE

  • DATETIME

  • DECIMAL[(M[,D])]

  • SIGNED [INTEGER]

  • TIME

  • UNSIGNED [INTEGER]

So just follow the guide:

 SELECT CAST(CAST(myColumn AS DECIMAL(5,2)) AS SIGNED) FROM myTable 

or

 SELECT CAST(CAST(myColumn AS DECIMAL(5,2)) AS UNSIGNED) FROM myTable 
+3
source share

This request works on the concept of a nested role.

cast (sum (cast (Column_name int) + cast (Column_name as int)) as bigint) as payment from table_name

0
source share

All Articles