SQL Server - Select column where range is given in the column description

sql-server-2008

Solution

If I've got it right:

WHERE 
CAST(SUBSTRING(Description,3,CHARINDEX('K',Description)-3) AS INT)
BETWEEN 10 and 40

SQL Fiddle demo

Assuming your comment to this answer the first position isn't fixed so in this case you should use PATINDEX() function in MSSQL:

WHERE 
    CAST(SUBSTRING(Description,
                    PATINDEX('%[0-9]%',Description), 
                    PATINDEX('%[0-9]K%',Description)-
                    PATINDEX('%[0-9]%',Description)+1)
         AS INT)
      BETWEEN 10 and 40

SQLFiddle demo

Problem

``` ID Description 51 SY10K40F 18 SY20K40F 12 SY30K40F 28 SY40K40F 34 SY100K40H 35 SY240K40H 36 SY300K40H ``` I have to select only those id for which description range is `10K to 40K`. Note - Id is primary key and from description we are getting 10k,20k etc.

Original source