Jump to content

How to convert varchar to number in sql statement?


Skylight_lady

Recommended Posts

Hi, i have a mysql table which is a varchar string. I have tried to get the following sql statement to work on my localhost without any luck.

 

SELECT * FROM users WHERE ID = '$ID' AND subscription <> 0 AND subscription <> 'admin' ORDER BY CONVERT(INT, subscription) DESC

 

If i use the following statement:

SELECT * FROM users WHERE ID = '$ID' AND subscription <> 0 AND subscription <> 'admin' ORDER BY subscription DESC

 

It works fine but, they are in the wrong order as i have numbers stored in the varchar and one text as shown in the sql statement above. Any advice would be appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.