1

Running into the following error in MySQL. I have tried using convert as well with no luck. The customer would like to be able to filter data where a customer ID will be something like: BOB102, REB293, REC203. I will need to pretty much be searching for customer numbers > 200, and so on.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTEGER)) > 0 )' at line 6

SELECT `orders_jobs`.* 
FROM (`orders_jobs`) 
INNER JOIN `orders_users` ON `orders_jobs`.`customer` = `orders_users`.`id` 
WHERE `orders_jobs`.`active` = 1 
AND `orders_users`.`active` = 1 
AND ( CAST(orders_users.cust_number AS INTEGER)) > 0 )

Now these may not always be 3 string characters long it might be 4 also, ie: BKER2938

NOTE: As Edga mentioned, I needed to use UNSIGNED instead of integer, but because of the characters it is converting all to 0 instead, is there possibly a different method?

Data Examples (for the field cust_number): MTQ32499,BGM31620,RES42935,CAM31717,CRED31672 (note the last one is 4 chars. I believe it will only be 3 or 4 characters long)

I need to return only the customers who have cust_number > 40000

4

1 回答 1

1

你应该使用

CAST AS SIGNED

或者

CAST AS UNSIGNED

更多信息在这里

- 编辑

作为一种解决方法,如果最后 5 个字符始终是数字,则可以使用SUBSTRING

于 2012-12-27T16:50:51.780 回答