Search code examples
sqlsql-server-2008-r2integersubstringnvarchar

Substring sql nvarchar value from start to first non-int character


Have a numeric nvarchar values with some "extra-symbols" For example 1/2, 9/6, 14A They allways starts with number.
How can I substring this "extra-symbols" values from start to index of first non-int character? The example line must be 1, 9, 14
Something like

SUBSTRING(Value, 0, CHARINDEX(Value, /*Here must be all symbols except numbers*/))

Solution

  • Please try the query:

    SELECT LEFT(ColumnName,PATINDEX('%[^0-9]%', ColumnName+'a')-1) FROM TABLE