Why am I getting a syntax error when using CAST in MySQL?

I am using MySQL workbench v5.2.44 CE. I run it against a local installation of MySQL 5.5.

I try to use the CAST function, but keep getting the following error:

Syntax error, unexpected INT_SYM

It does not matter what the source and target date types are. The only time it does not give me an error is that the target data type is DECIMAL . Here is an example:

 SELECT CAST(IFNULL(comboCount, 1) * COUNT(partID) AS INT) INTO comboCount FROM productOption 

I tried everything but nothing works.

+4
source share
1 answer

Try to do the math outside:

 SELECT CAST(IFNULL(comboCount, 1) AS INT) * COUNT(partID) INTO comboCount FROM productOption 

If this does not work, try CAST as UNSIGNED ; not INT .

+2
source

All Articles