Counting occurances of a string in a field..

Counting occurances of a string in a field..

Post by Ryan William » Mon, 02 Apr 2001 09:07:25



Hi there..

This is actually a query for mySQL but I figured I'd see if there was a SQL
Server command that'd do the job cos there'd be half a chance of a mySQL
equivalent.. or if it comes to it i'll just use SQL server for the site..
(got a copy, just not quite got round to playing with it yet)

Cheers,

Ryan

 
 
 

Counting occurances of a string in a field..

Post by Meade Robbo » Mon, 02 Apr 2001 08:37:59


Ryan,

SQL Server has a CHARINDEX string function that returns the starting
position of a string within another string, and allows you to set a starting
position. You can loop the results until the result = 0 to count the total
number of occurrences.

There are significant differences between SQL Server and MySQL; do not
assume they have the same functionality. If you want to find answers to
MySQL questions, this NG is probably not a very good resource.

I think you'd be surprised at the significant differences between the
products, even though they both 'do SQL' - I would compare MySQL
functionality closer to Access than SQL Server.

-Meade


Quote:> Hi there..

> This is actually a query for mySQL but I figured I'd see if there was a
SQL
> Server command that'd do the job cos there'd be half a chance of a mySQL
> equivalent.. or if it comes to it i'll just use SQL server for the site..
> (got a copy, just not quite got round to playing with it yet)

> Cheers,

> Ryan


 
 
 

Counting occurances of a string in a field..

Post by Ryan William » Mon, 02 Apr 2001 09:59:23


Cheers for the help mate.. I checked and there is a similar function in
mySQL. The reason i tried here is that I got no joy at devshed.com and NTL
doesnt have any mySQL newsgroups, so i thought I'd try this.

I think i should perhaps point out that mySQL is loads better than Access.
I've been having to maintain some sites where the previous coder used Access
and Coldfusion and it's a truly horrendous combination, wheras php and mySQL
are brilliant. I do want to try php and MS SQL though cos i like to learn
new stuff :) It's the whole point of doing web development, and one of the
reasons I love my job so much :)

Cheers again,

Ryan


> Ryan,

> SQL Server has a CHARINDEX string function that returns the starting
> position of a string within another string, and allows you to set a
starting
> position. You can loop the results until the result = 0 to count the total
> number of occurrences.

> There are significant differences between SQL Server and MySQL; do not
> assume they have the same functionality. If you want to find answers to
> MySQL questions, this NG is probably not a very good resource.

> I think you'd be surprised at the significant differences between the
> products, even though they both 'do SQL' - I would compare MySQL
> functionality closer to Access than SQL Server.

> -Meade



> > Hi there..

> > This is actually a query for mySQL but I figured I'd see if there was a
> SQL
> > Server command that'd do the job cos there'd be half a chance of a mySQL
> > equivalent.. or if it comes to it i'll just use SQL server for the
site..
> > (got a copy, just not quite got round to playing with it yet)

> > Cheers,

> > Ryan