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)

Find the Nth Occurrence of a Character in a String

By Cade Bryant,

T-SQL's CHARINDEX() function is a useful for parsing out characters within a string.  However, it only returns the first occurrence of a character.  Oftentimes one needs to locate the Nth instance of a character or a space, which can be a complicated task in standard T-SQL.  This function I wrote, imaginatively named CHARINDEX2(), allows one to do this.  It receives, as arguments, the target string or character, the string to be searched, and the occurrence of the target string/character.

Total article views: 3925 | Views in the last 30 days: 18
 
Related Articles
SCRIPT

Trim Non-Alpha characters from string

Trim Non-Alpha characters from string

FORUM

Random 64 Characters alphanumeric String

Random 64 Characters alphanumeric String

SCRIPT

ASCII Character Groups in String

Powerful function to find strings containing or excluding classes of ASCII characters.

FORUM

Conversion failed when converting datetime from character string

Conversion failed when converting datetime from character string

FORUM

Find last occurence of a character within a string

Find last occurence of a character within a string

Tags
miscellaneous    
t-sql    
 
Contribute

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
Editor, SQLServerCentral.com

Already a member? Jump in:

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