Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Salect Max(varchar) - sql server 2008

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2009-07-14 : 07:44:34
Iam using sqlserver2008, now I want to find a maximum value of the field of "mpr_no" but the field type varchar...
So how to find the max?

select max(mpr_no) from mprmst......?

Thanks

Paramu @ PARANTHAMAN

paramu
Posting Yak Master

151 Posts

Posted - 2009-07-14 : 07:55:57
Just I got the answer..let it may useful to someone else

select max(0+mpr_no) from mprmst

Paramu @ PARANTHAMAN
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-14 : 08:27:59
This will crash if you have "bad" data in column mpr_no.
i.e. 0+'some1234bad data' gives you much fun


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-14 : 08:33:45
select max(0+mpr_no) from mprmst
where mpr_no not like '%[^0-9.]%'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-14 : 08:36:25
quote:
Originally posted by madhivanan

select max(0+mpr_no) from mprmst
where mpr_no not like '%[^0-9.]%'

Madhivanan

Failing to plan is Planning to fail


déjà vu


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-14 : 08:42:16
quote:
Originally posted by webfred

quote:
Originally posted by madhivanan

select max(0+mpr_no) from mprmst
where mpr_no not like '%[^0-9.]%'

Madhivanan

Failing to plan is Planning to fail


déjà vu


No, you're never too old to Yak'n'Roll if you're too young to die.




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -