Selecting specific characters from a column

  • I am trying to figure out how to select a specific character from a list of values that I have in a table. For example, my data is configured something like the following:

    DESC G/L F100 DESCRIPTION LOCATION

    DESC G/L R100 DESCRIPTION LOCATION

    DESC G/L B100 DESCRIPTION LOCATION

    DESC G/L F135 DESCRIPTION LOCATION

    DESC G/L F199 DESCRIPTION LOCATION

    I want to select a specific character from the results for example:

    WHERE [POSITION 10] = 'F' or WHERE [POSITION 11] BETWEEN 1 AND 5

    I know that POSITION is not a recognized function or value for SQL so I was wondering how I could achieve this. Thanks!!

  • SELECT *

    FROM mytable

    WHERE SUBSTRING(mydata,10,1) = 'F' AND SUBSTRING(mydata,11,1) IN ('1','2','3','4','5')

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Thank you!! This is perfect and worked out great.

    Cheers!

    Tim

  • Or:

    SELECT *

    FROM mytable

    WHERE mydata LIKE '_________F[1-5]%'

    _____________
    Code for TallyGenerator

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply