Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 String Function, is there a better way?

Author  Topic 

dukey07
Starting Member

16 Posts

Posted - 2003-08-08 : 12:16:32
I'm trying to get a count of the occurences of a sub string within a string. Is this the the way to do it?

Declare @test varchar(255)

Select @test = 'blah blah@bla bla bla@'

Select Len(@test) - Len(Replace(@test,'@',''))

nr
SQLTeam MVY

12543 Posts

Posted - 2003-08-08 : 12:42:00
It's the easiest and probably fastest.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-08-08 : 14:54:42
uh uh ... here comes Jay with a "set-based" method ... I can feel it ....




- Jeff
Go to Top of Page

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2003-08-08 : 14:58:26
That hurts ... placing set-based in quotes as though it's not "real" or "valid" ...

Jonathan
{0}
Go to Top of Page

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2003-08-08 : 14:58:59
Don't forget to divide by the length of the substring.

Jonathan
{0}
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-08-08 : 15:59:07
Actually, you're right, i mis-used the quotes!


I meant to use them like this:

Jay is a "well-respected" and "accomplished" guy.






- Jeff
Go to Top of Page
   

- Advertisement -