Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Location
    India
    Posts
    5

    Unanswered: String methods in SQL

    Hi there,
    I need to do a parsing within a stored procedure.
    I need to split the sub string between two ANDs and/or ORs.
    Is there any way to do a find on the string if yes please let me know.

  2. #2
    Join Date
    Oct 2003
    Location
    Switzerland
    Posts
    140
    You can use CHARINDEX or PATINDEX to lookup the starting position of a string within a string.

    Example
    =====
    declare @a char(20)
    declare @sp int
    set @a = 'YES OR NO'
    set @sp = charindex('OR',@a)
    print substring(@a, 1, @sp-1)
    print substring(replace(@a,'OR',''),@sp, 20)

    returns
    ====
    YES
    NO

    You might want to throw in a little error handling in case @sp returns 0 (meaning OR was not found), and you might want to verify your collating sequence (case sensitive or not, is OR = or...)

Posting Permissions

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