I need a way to detect rows in a table in MSSQL using varchar entries that cannot be converted to int.
The system I'm working on uses the editable varchar field in one place and joins the integer column in another place. If the varchar field receives an invalid number in it (something is empty, with alpha or characters, or will be more than 2.1 billion (maximum int size)), another request fails, saying that the xyz value overflowed the int column or may not converted.
I came up with the following partial solution for finding offensive records:
select g.id, g.membernumber from groups g left join secondary_groups sg on sg.id=g.id where convert(bigint, g.membernumber) > 2147483647 or isnumeric(g.membernumber) = 0
This works fine for most things, but then I realized that it could be defeated if the varchar value exceeds 'bigint'. Is there a more general method for finding these types of records instead of using cast / convert? It would be great if there was a built-in method for "IsInt ()", but alas ...
source share