Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

INSTR Function

By Nagabhushanam Ponnapalli,

INSTR searches string for substring. --> position is an integer indicating the character of string where SQL Server begins the search. -->If position is negative, SQL Server counts and searches backward from the end of string. occurrence is an integer indicating which occurrence of string SQL Server should search for. The value of occurrence must be positive. The function returns an integer indicating the position of the character in string that is the first character of this occurrence. The default values of both position and occurrence are 1, meaning SQL Server begins searching at the first character of string for the first occurrence of substring. The return value is relative to the beginning of string, regardless of the value of position, and is expressed in characters. If the search is unsuccessful (if substring does not appear occurrence times after the position character of string) the return value is 0.

Total article views: 1158 | Views in the last 30 days: 4
Related Articles

Find the position of all occurrences of an expression within a string

This iTVF returns both the relative and the actual positions of ALL occurrences of a string within a...


SQL BLOG: First Occurrence Of Character In a String

Scenario:  We need to find the first occurrence of character ie non numeric data in the string ...


Get given character's position from a string

Get given character's position from a string


String Search

Search for a string value within columns of data types CHAR, NCHAR, NTEXT, NVARCHAR, TEXT, VARCHAR, ...


Extarcting string after and before a Character/Pattern

Finding characters/string before and after some character or pattern


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones