Search code examples
sql-servert-sqlmaxnumericisnumeric

T-SQL: Get max numeric value in char field having both numbers and letters


In a SQL Server 2008 database table I have a char field that has both numbers and letters. I.e.:

TST
842
UUT
124
674
XTM
763

I need to find the maximum integer in that field. So in the above example I would return "842".

I know how to test for whether the value is numeric or not (ISNUMERIC()function), but I can't figure out how, using that test, to return the maximum integer value.


Solution

  • SELECT MAX(yourcol) FROM T WHERE ISNUMERIC(yourcol)=1 ;