« Previous Next »

Answered Thread: CharIndex unavailable?

Last post 07-29-2008 2:24 AM by yellowdog.dave. 1 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (2 items)

Sort Posts:

  • 07-28-2008, 3:33 PM

    • jcAgora
    • Not Ranked
    • Joined on 07-28-2008, 7:25 PM
    • Posts 3

    CharIndex unavailable?

    Hi there, I tried to parse the info in "cs-uri-stem",

    In "cs-uri-stem" it contain a string like " /Demodir/_233_demo.gif"

    I just want to parsed the "233" . So I used CharIndex.
     

    I tested in CharIndex on SQL and it worked, but once I run it in LogParser  it failed. The error message is as following:

    Error: Syntax Error: <field-expr>: cannot find a vaild <field-expre>:'CHARINDEX('_',') 

    This is my query: 

    LOGPARSER -i:IISW3C "Select LogRow, time, c-ip, cs-method,cs-uri-stem,SUBSTR(cs-uri-stem, CHARINDEX('_', cs-uri-stem) + 1, (CHARINDEX('_', cs-uri-stem,CHARINDEX('_', cs-uri-stem) + 1) - CHARINDEX('_', cs-uri-stem) - 1)) as ContentId
      from C:\WINDOWS\system32\Logfiles\W3SVC1\ex080725.log where cs-uri-stem Like '/DemoWeb/Images/Up/EML/%'" -o:datagrid  
     

    any suggestion is welcome.

    Thanks in advanced,

    ---Joe 

  • 07-29-2008, 2:24 AM In reply to

    • yellowdog.dave
    • Top 75 Contributor
    • Joined on 07-18-2008, 3:17 AM
    • Johannesburg, South Africa
    • Posts 84

    Answered Re: CharIndex unavailable?

     Hi Joe,

    The easiest way to get this information out of the string is to use EXTRACT_TOKEN. In this particular instance, I would parse the string from the end, so I would use negative substring values, so this would look something like this;

    EXTRACT_TOKEN(cs-uri-stem,-2,'_') 

    Refer to logparser.chm for any further info on this and the EXTRACT functions - I find them very useful and simple. Good luck. 

    Cheers, Dave 

    Yes, dear
Page 1 of 1 (2 items)
Microsoft Communities