Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get max value?

Status
Not open for further replies.

seahorse123

Programmer
Jul 25, 2005
39
0
0
US
In the table, there is a column (col varchar 20).
I have these values saved:
1_1
1_2
1_9
1_14

now I want to get the max value "1_14", if the column is INT type, I can easily use MAX(col), but it's the varchar type, if I use MAX(col), I will get "1_9", so how to get the max value in the varchar type? thanks.
 
Code:
select savedvalue
  from yourtable
 where 0+trim(leading '1_' from savedvalue)
  = ( select max(
       0+trim(leading '1_' from savedvalue)
                )
       from yourtable )
untested :)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top