Pattern Matching

  • Hi,

    I have some sample data such as:

    AB123 Text Text Text

    Text Text Text AB456

    Text Text CD789 Text

    CD010_Text Text Text

    Text Text_EF999 Text

    Text Text_EF888_Text

    I want the output as:

    Code

    ------------

    AB123

    AB456

    CD789

    CD010

    EF999

    EF888

    What is the best way to write a T-SQL Query to achieve this?

  • It totally depends on what is the 'text'. Try patindex()

    declare @txt varchar(100)

    set @txt ='Te33 Text CD789 Te6t'

    select substring(@txt,patindex('%[A-Z][A-Z][0-9][0-9][0-9]%', @txt),5)

    Rgds

    Serg

Viewing 2 posts - 1 through 1 (of 1 total)

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