Check if a variable contains any non-numeric digits in SQL Server Check if a variable contains any non-numeric digits in SQL Server sql sql

Check if a variable contains any non-numeric digits in SQL Server


Check for any characters that are not in the range 0 to 9

^ is not in LIKE expressions

IF @rptID LIKE '%[^0-9]%'   --throw error 


There is also an ISNUMERIC function in MSSQL if you're using version 2008 or later.

mentioned link

IF (not ISNUMERIC(@rptID) = 1)    THEN throw Error