Listing 1: Code Example for Retrieving Only Numeric Part of String DECLARE @str nvarchar(255) SET @str = N'qq23.34' -- 23 --SET @str = null -- null --SET @str = N'' – empty string --SET @str = N'%' – empty string --SET @str = N'2' -- 2 --SET @str = N'abc' – empty string --SET @str = N'a23b' -- 23 /* Add a non-numeric string terminator. */ SELECT @str = @str + N'X' /* Remove all non-numerics from the head of the string by finding the first numeric. */ SELECT @str = right(@str,len(@str) - PATINDEX(N'%[0-9]%',@str) + 1) /* Remove all non-numerics from the tail of the string by finding the first non-numeric. */ SELECT @str = left(@str, PATINDEX(N'%[^0-9]%',@str) - 1) SELECT @str