I am using MySQL workbench v5.2.44 CE. I am running it against a local MySQL 5.5 install.
I am trying to use the CAST
function, but keep getting the following error:
syntax error, unexpected INT_SYM
It doesn't matter what the source and target date types are. The only time it doesn't give me an error is when the target datatype is DECIMAL
. Here is an example:
SELECT CAST(IFNULL(comboCount, 1) * COUNT(partID) AS INT) INTO comboCount
FROM productOption
I have tried everything, but nothing seems to work.
MySQL CAST() FunctionThe CAST() function converts a value (of any type) into the specified datatype.
The MySQL CAST() function is used for converting a value from one datatype to another specific datatype. The CAST() function accepts two parameters which are the value to be converted and the datatype to which the value needs to be converted.
The MySQL 1064 error is a syntax error. This means the reason there's a problem is because MySQL doesn't understand what you're asking it to do. However, there are many different situations that can lead to this type of miscommunication between you and your database.
Try to do the math outside:
SELECT CAST(IFNULL(comboCount, 1) AS INT) * COUNT(partID) INTO comboCount
FROM productOption
If that doesn't work, try to CAST
as UNSIGNED
; not INT
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With