August 28, 2011

Use of CHARINDEX in SQL Server

CHARINDEX returns the first position of the specified expression in a string.
We can understand this in a more better way by an example.

image 

Here i am searching ‘G’ in ‘Google Blogger’ of course result should be 1.
What if expression will not be present in character string, in that case result will be 0.

image 

We can also search entire word in a string.

image 

We can make our search case sensitive also.See how we can do this.

image

That’s It.
Enjoy Reading.

No comments:

Post a Comment