Click here to Skip to main content
16,010,470 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody
I am storing number values like 1,23...99 in a field, and this field have character data type.
I need max value from this field but due to character data type it is not returning correct value.
If u have any suggestion then please tell me..
Thanks in advance
Posted

Never store numbers in a character based field, or any form of comparison cannot work correctly. For example, the character based value "10" is before the character based value "9".

By preference, store numeric values in numeric fields.
If you can't change the table definition (and I would, it is a lot more efficient and prone to errors) you can CAST the values:
SQL
SELECT MAX(CAST(dat as int)) FROM myTable
 
Share this answer
 
CAST (or CONVERT) your text result to a numeric one and then use MAX.
 
Share this answer
 
Your problem is similar to this person :

Find maximum value from any table[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900