Selecting varchar values from a column

user2271146

I'm working on SQL 2008 and have a table with 1000's of codes in it - a sample would be:

D37
D37.0
D38
D38.0
D39
D39.0
D3A
D3A.0
D40

What I need to do is select the values between D37 and D40. However, I do not want the D3A values (or D3B or D3C for that matter). I have tried the following:

SELECT Code
FROM Table
WHERE Code BETWEEN 'D37' AND 'D40'

However, this get all the codes listed above, including the D3A codes.

Is there a way to exclude the codes that do not fall in the 37-40 range?

Tab Alleman

Assuming that the single-letter convention is followed throughout, and there aren't any more weird characters than shown in the data, you can do this:

WITH cte AS (
    [MyColumn]
  , SELECT SUBSTRING([MyColumn],2,LEN([MyColumn)-1) AS Code
  FROM MyTable
  WHERE ISNUMERIC(SUBSTRING([MyColumn],2,LEN([MyColumn)-1)=1
)
SELECT [MyColumn]
FROM cte
WHERE CAST(Code AS float) BETWEEN 37 AND 40

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selecting distinct values from a column in Peewee

From Dev

Selecting particular values from a column in a dataframe

From Dev

MySQL : Selecting values from a specific column is very slow

From Dev

SQL - Selecting unique values from one column then filtering based on another

From Dev

Selecting Top N Column Values per Row from a data frame

From Dev

selecting a column values from a Table using LINQ (Entity Framework)

From Dev

SQL - Selecting a column from another table twice with different values

From Dev

SQL - Selecting unique values from one column then filtering based on another

From Dev

Selecting distinct values from multiple column of a table with their count

From Dev

Selecting specific rows from a large dataset using column values

From Dev

PowerShell - Selecting individual values from column in sub-array

From Dev

Selecting from table where one column holds many data types as varchar

From Dev

MySQL - Select only numeric values from varchar column

From Dev

How to find int values from a comma separated varchar column SQL

From Dev

Selecting from table into a column

From Dev

Selecting records from column

From Dev

Selecting values from a combobox

From Dev

Selecting values from List

From Dev

Selecting values from a combobox

From Dev

Selecting rows with specific values in a column

From Dev

MySQL Count values from one column with selecting a value from another column

From Dev

Selecting values from a table where values from one column is divided into multiple columns

From Dev

Selecting data from table where sum of values in a column equal to the value in another column

From Dev

Selecting a table and filtering by several values from one column as well as a value from another

From Dev

selecting elements from a column in Excel

From Dev

Selecting Values from different arrays

From Dev

Selecting random values from dictionary

From Dev

selecting values from javascript in a for loop

From Dev

selecting values from a reference table

Related Related

  1. 1

    Selecting distinct values from a column in Peewee

  2. 2

    Selecting particular values from a column in a dataframe

  3. 3

    MySQL : Selecting values from a specific column is very slow

  4. 4

    SQL - Selecting unique values from one column then filtering based on another

  5. 5

    Selecting Top N Column Values per Row from a data frame

  6. 6

    selecting a column values from a Table using LINQ (Entity Framework)

  7. 7

    SQL - Selecting a column from another table twice with different values

  8. 8

    SQL - Selecting unique values from one column then filtering based on another

  9. 9

    Selecting distinct values from multiple column of a table with their count

  10. 10

    Selecting specific rows from a large dataset using column values

  11. 11

    PowerShell - Selecting individual values from column in sub-array

  12. 12

    Selecting from table where one column holds many data types as varchar

  13. 13

    MySQL - Select only numeric values from varchar column

  14. 14

    How to find int values from a comma separated varchar column SQL

  15. 15

    Selecting from table into a column

  16. 16

    Selecting records from column

  17. 17

    Selecting values from a combobox

  18. 18

    Selecting values from List

  19. 19

    Selecting values from a combobox

  20. 20

    Selecting rows with specific values in a column

  21. 21

    MySQL Count values from one column with selecting a value from another column

  22. 22

    Selecting values from a table where values from one column is divided into multiple columns

  23. 23

    Selecting data from table where sum of values in a column equal to the value in another column

  24. 24

    Selecting a table and filtering by several values from one column as well as a value from another

  25. 25

    selecting elements from a column in Excel

  26. 26

    Selecting Values from different arrays

  27. 27

    Selecting random values from dictionary

  28. 28

    selecting values from javascript in a for loop

  29. 29

    selecting values from a reference table

HotTag

Archive