Monday, March 26, 2012

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 regardsThe patindex function should work for you here. But, it will only give you the location of the first one. Syntax:
PATINDEX ( '%pattern%' , expression )|||I wonder what he difference is?

SELECT PATINDEX ( '%/%' , 'ABCDEFG1239/1002STJ' )
SELECT CHARINDEX ( '/','ABCDEFG1239/1002STJ' )|||PatIndex() allows SQL Server regular expressions. CharIndex() only allows literals.

-PatP|||Who was that masked man?|||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

No comments:

Post a Comment