Capturing Certain Text in a field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • benchpolo
    New Member
    • Sep 2007
    • 142

    Capturing Certain Text in a field

    I have a set of data that i need to only capture part of it. I can use RIGHT(<FIELD>,< LENGTH>) or LEFT(<FIELD>,<L ENGTH>), but i will not work bec the length of the data varies. For example,

    Description

    EL PASO (OLD CODE)
    DELAWARE(OLD CODE)

    I only need to capture EL PASO and DELAWARE excluding (OLD CODE), but i'm stuck in trying to figure out the correct TSQL syntax. Your help is much appreciated.

    Thanks.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Is the "(OLD CODE)" a fix value or does it change every record?

    ~~ CK

    Comment

    • benchpolo
      New Member
      • Sep 2007
      • 142

      #3
      It is a fix value.

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        try something like this:

        Code:
        SELECT description, fixed_desc = replace(description,'(OLD CODE)','')
        FROM YourTable
        It just removed the string "(OLD CODE)" on your data.

        Happy Coding!!!

        ~~ CK

        Comment

        Working...