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 Nth Occurrence of Character Function V3

By Piquet,

In the tradition of best practice & code improvement, a third iteration of a script that finds the Nth occurrence of a Target string within another string (Original author unknown, V2 author vextant).

This version returns zero if an Nth occurrence is not found (similar to V1), but also provides the ability to search the string Right to Left so that you can find the last occurrence, 2nd to last occurrence, etc.
The code has also been simplified.

Arrrrrr!!
(It's international Talk Like a Pirate Day today)

Total article views: 401 | Views in the last 30 days: 1
 
Related Articles
BLOG

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 ...

SCRIPT

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...

FORUM

String Parsing

Find the second occurrence of \ in a string and replace everything after with blank space

FORUM

Search for string occurrence

Can this be done? Does anyone know of a tool or command I could use that can find all occurrences o...

FORUM

Count # occurrences of one string inside another

Comments posted to this topic are about the item [B]Count # occurrences of one string inside another...

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