Home > Alter, SQL Queries, SQL Server, T-SQL, Tips & Tricks > Search for a pattern in sql server using patindex() and Charindex()

Search for a pattern in sql server using patindex() and Charindex()

Although these functions are not commonly used, these are really powerful in searching a pattern and returning the location of text/ string/ pattern. By understanding the functionality of both the string functions, we will be able to understand the difference as well.

PATINDEX()

The function searches for a pattern in a string / expression and returns the starting position of the first occurrence of the pattern. It works similar to the LIKE operator in any query.

The general syntax is

PATINDEX ( ‘%pattern%’ , expression )

You might have already noticed the ‘%’ symbols used in the pattern. These are important, as I mentioned earlier, use the same syntax as used for searching by  LIKE operator.

Continue Reading …

Advertisements
  1. October 20, 2010 at 6:38 am

    This is second incident that I am scanning anything about modifying websites with the system. It seems that you are an super expert blogger. Your post is an excellent example of why I continue coming back to study your good quality content that is forever updated.

  2. November 22, 2012 at 4:22 am

    I will right away snatch your rss feed as I can’t find your e-mail subscription link or newsletter service. Do you have any? Please let me realize so that I could subscribe. Thanks.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: