October 20, 2011

PATINDEX in SQL Server

PATINDEX returns starting position of first occurrence of a pattern in a string,or zero if it is not available in string.

image

Here i am trying to find ‘%S%’ in string ‘SQL Server’ of course output should be 1.

Let’s try to find ‘%Q%’ in same string.Guess what output should be.

image
Now i want to search SQL in same string.

image
It is very clear from output first occurrence of ‘SQL’ in string is starting from 1st position.
So output should be 1.

That’s It
Enjoy Learning.

No comments:

Post a Comment