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

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

tighter approach to counting strings in strings

By John,

Saw Mike's routine for counting occurences of a string in a string and I thought I'd offer a simpler solution.

Simply replace the occurence with null and use length differences as shown.

NOTE: len may ignore trailing spaces, so this can be made more solid by adding some non printable char (less likely to interfere with operation) to the end of the string being searched. (e.g. 'seach string here     ' ->
'seach string here     $' )

This can be wrapped in a function for utility.

Total article views: 61 | Views in the last 30 days: 2
 
Related Articles
FORUM

string Comparison.

'string' = 'string___' ???

FORUM

Manipulate String

String Output

FORUM

csv string

csv string

FORUM

string formatting

String Formatting

FORUM

parse/split string

string manipulation

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