Jump to content

Cast() Question


zebe

Recommended Posts

Hi,

I am working on a database that has a table of class sections. Within this table there is a field called section code, i.e. the class number. Normally I would have made this field have type int, but I needed to make it a varchar field because there are about 6 sections that have non numerical section codes.

On the original server I was able to order by using the CAST() function on the section_code field:

[code]$sql = "SELECT id, section_code, instructor, ins_email, ins_phone, mentor_1, mentor_2, mentor_1_email, mentor_2_email,
day_time, location, LC_focus FROM uri_101_sections ORDER BY CAST(section_code as unsigned)
"; [/code]

I just recently moved this database to a new server and it no longer functions in the same way, in fact I get the following error:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You have an error in your SQL syntax near '(section_code as unsigned) ' at line 2[/quote]

Does anyone know why this could be occurring or have an alternate solution for this problem? Thank you so much for any help, I appreciate it!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.