I need a substring query that will return certain values from a character string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ken Jones
    New Member
    • Sep 2010
    • 9

    I need a substring query that will return certain values from a character string

    Table URL_3 consist of the following 2 columns of information being Record No and URL

    Code:
    No                         URL
    1   http:/publishing/45/100006_f.SAL_Local.html
    2   http:/publishing/45/100006_f.SAL_Area.html
    I need a substring query that will return the values of Local and Area from column URL of Table URL_3 into an additional column of information.
    I was looking for the solution, shown below, that tried to delimit the desired values of the underscore(_) and the period(.) that preceeded and followed the desire values of Local and Area that I was trying to extract. I could not get this query to work and was hoping it could be made to work. I would appreciate any solution to this problem

    Code:
    SELECT Right([URL],InStr([URL],_  .)-1) 
    FROM URL_3;
    Last edited by NeoPa; Sep 20 '10, 01:30 PM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    Try :
    Code:
    SELECT [No]
         , [URL]
         , Mid([URL], 
               InStr(1, [URL], 'SAL_') + 4, 
               InStr(1, [URL], '.html') -
               InStr(1, [URL], 'SAL_') - 4) AS URLBit
    FROM   [URL_3]

    Comment

    • Mariostg
      Contributor
      • Sep 2010
      • 332

      #3
      Under the assumtions that it is either Area or Local, the following could work too:
      Code:
      SELECT IIf(InStr(URL,"Local"),"Local","Area") AS MyString
      FROM URL_3;

      Comment

      Working...