If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > SELECT MAX(CAST(string AS SIGNED)) fails

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-19-04, 04:14
simonrundell simonrundell is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
SELECT MAX(CAST(string AS SIGNED)) fails

I have a table in which there is a column containing values to populate a dropdown box. Depending on the DROPDOWN_SUBJECT the DROPDOWN_VALUE may be text or a number, so the column is a varchar(50).

In a certain context, I want to extract the last entry for a particular numeric type

However SELECT MAX(DROPDOWN_VALUE) FROM ...
is fine until the values goes over 10, where it will ALWAYS return 9

I was expecting data type conversion to be automatic, so I tried casting it to integer

SELECT MAX(CAST(DROPDOWN_VALUE AS SIGNED)) FROM ...
fails with syntax error. Same for UNSIGNED. Even in a basic query window CAST("1" AS SIGNED) gives the same error.

It must be obvious, but I am really, really stuck. Any help or pointers would be gratefully received.

Why would it work for numbers below 10 and then get stuck like this after.

example:

SQL-query :

SELECT MAX( CAST( DROPDOWN_VALUE AS SIGNED ) ) AS last_value
FROM `DROPDOWN`
WHERE DROPDOWN_SUBJECT = 'POSTTYPE'

MySQL said:

#1064 - You have an error in your SQL syntax near '( DROPDOWN_VALUE AS SIGNED ) ) AS last_value
FROM `DROPDOWN`
WHERE DROPDOWN_' at line 1


Fr. Simon Rundell
Parish of the Holy Spirit
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On