Select Filter

  • I need to return all part numbers in a table that are based on the following pattern:

    8675G309

    The fist four characters are numeric, the fith alpha, and the remaining two are numeric.

    How would I go about finding these? Any help will be greatly appreciated.

  • Use LIKE

    SELECT ..

    FROM mytable

    WHERE PartNumber LIKE '[0-9][0-9][0-9][0-9][A-Za-z][0-9][0-9]'

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • Worked like a charm! Thanks.

  • Mark-101232 (5/16/2012)


    Use LIKE

    SELECT ..

    FROM mytable

    WHERE PartNumber LIKE '[0-9][0-9][0-9][0-9][A-Za-z][0-9][0-9]'

    If your collation is case-insensitive (default ), you don't need to specify both A-Z and a-z.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Good to know. Thanks again.

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

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