15,960,623 members
See more:
Hello,
My sql datas are:
T863
356
F5963
563
3659

I want to get codes are between 355 to 564
but i get error from T863

How can i fix this problem?

What I have tried:

some google search but there is any example for this situation
Posted
Updated 12-Nov-17 23:22pm

## Solution 1

Short answer - you cannot - cast &/or convert will return an error if the value fails to convert to an integer.
Long answer - the below will work;
SQL
```-- Declare a Table variable
DECLARE @MyTableVariable TABLE
(ErrorNumber INT)
INSERT INTO @MyTableVariable
SELECT CAST(ErrorNumber AS INT) AS ErrorNumber
FROM MyTable
WHERE ISNUMERIC(ErrorNumber) = 1
-- Query the Table Variable
SELECT ErrorNumber
FROM @MyTableVariable
WHERE ErrorNumber BETWEEN 355 AND 564```

Kind Regards

## Solution 2

```CREATE TABLE #temp(mixedvalues VARCHAR(10));
INSERT INTO #temp
VALUES('T863'),
('356'),
('F5963'),
('563'),
('3659'),
('340T');

;WITH CTE AS(
SELECT SUBSTRING(mixedvalues,
PATINDEX('%[0-9]%', mixedvalues),
(LEN(mixedvalues)-PATINDEX('%[0-9]%',REVERSE(mixedvalues))+1)) AS
NumericValues FROM #TEMP)
SELECT * FROM CTE WHERE NumericValues between 355 and 1000;
-----------------
NumericValues
--------------
NumericValues
863
356
563```

v2