Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2002
    Location
    USA-CA
    Posts
    36

    Arrow Unanswered: Sybase string function is needed!!!

    Hi All,
    I need some assistance.

    I have a string "First | Second | Third | Fouth | Etc "
    I need to write Sybase expression that will return
    a third string part ("Third") after delimeter "|".
    How to implement it?

    Thanks a lot in advance!!!
    John Smith

  2. #2
    Join Date
    Mar 2001
    Location
    Lexington, KY
    Posts
    606
    Hi John,

    Character string functions are located here:
    http://manuals.sybase.com/onlinebook...TextView/31320;pt=31320#X

    Sounds like you'd want to do a loop and use charindex to find the starting point of the third instance and the starting point of the 4th instance then use substring( mycolumn, starting point of third, ( starting point of fourth - starting point of third) as length )
    Thanks,

    Matt

  3. #3
    Join Date
    Apr 2002
    Location
    USA-CA
    Posts
    36

    Thumbs up Is it looks OK?

    declare @InpStr varchar(255), @bp int, @ep int, @tmpStr varchar(255), @strlen int, @theword varchar(255), @cx int, @nWord int
    select @InpStr = " | One | Two | Three | Four | Five | Six | "

    select @tmpStr = ltrim(rtrim(" | One | Two | Three | Four | Five | Six | "))
    select @nWord = 4
    select @cx = 1

    while (select @cx) <= @nWord
    begin

    select @strlen=char_length(@tmpStr)
    select @bp=charindex("|", @tmpStr)
    select @tmpStr=substring(@tmpStr, @bp+1, @strlen - @bp + 1)
    select @ep=charindex("|", @tmpStr)
    select @theword=ltrim(rtrim(substring(@tmpStr, 1, @ep - 1)))
    select 'TheWord = ', @theword
    select @cx = @cx + 1

    end

    go
    John Smith

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •