Monday, February 20, 2012

MAX() for non-HEX numbers

Hi,
I sit with a situation where I want to select the biggest number of a
field (varchar) which does NOT have a HEX Number in this field eg:
field
1
2
3E
A5
4
I would like to get 4 returned.
Any ideas ?
Thanx
Technically, 1, 2 and 4 are hex (as well as base 10 and octal). Perhaps you
want to consider only those values that do not have non-numerics?
Try:
select
max (field)
from
MyTable
where
field not like '%[~0-9]%'
Now, if you want numerical comparison of the values, then I'd change this
to"
select
max (cast (field as int))
from
MyTable
where
field not like '%[~0-9]%'
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"AlexC" <alex.caudron@.mail.co.za> wrote in message
news:1130238860.255680.184090@.g43g2000cwa.googlegr oups.com...
Hi,
I sit with a situation where I want to select the biggest number of a
field (varchar) which does NOT have a HEX Number in this field eg:
field
1
2
3E
A5
4
I would like to get 4 returned.
Any ideas ?
Thanx

No comments:

Post a Comment