Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2002
    Location
    Singapore
    Posts
    71

    Unanswered: Retriving Position In A Field

    Hi All.

    Is there a way to retrieve the position of a word, phrase or sign in a field?

    For example, Field content is ABCDEFG1239/1002STJ

    I would like to get the exact position of / which will be position 12.


    Thank you.

    Best regards

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    The patindex function should work for you here. But, it will only give you the location of the first one. Syntax:
    Code:
    PATINDEX ( '%pattern%' , expression )

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    I wonder what he difference is?

    Code:
    SELECT PATINDEX ( '%/%' , 'ABCDEFG1239/1002STJ' ) 
    SELECT CHARINDEX ( '/','ABCDEFG1239/1002STJ'  )
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    PatIndex() allows SQL Server regular expressions. CharIndex() only allows literals.

    -PatP

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Who was that masked man?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  6. #6
    Join Date
    Jun 2002
    Location
    Singapore
    Posts
    71
    Hello All.

    Thank you for your reply. I couldn't thank of you earlier because I was away to Europe on a business trip.

    I will try out your solutions today.

    Once again. Thank you.

    Best regards

Posting Permissions

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