count ocurencies of a string not row count

  • I think this is going to be one of those things that has an easy and elegant answer I just wasnt clever enough to think of...

    I want to count the occurrencies of a user entered string within a varchar column of the whole table...NOT THE ROWCOUNT as one row may contain the numerous times.

    Can think of numerous ways to do it on the ASP end is there an SQL solution...?

    Cheers

    Rolf

  • Try

    
    
    Select Sum((DataLength([ColumnName])-DataLength(RePlace([ColumnName],'SearchFor','')))/DataLength('SearchFor'))
    from Table
  • thats a good idea but its no good for wildcard searchs as it users string length which of course for a wildcard search would be different. Say you searched for THE but also wanted it to look for THERE etc.

    Any other ideas guys...? I still havent got anywhere..? Its one of those questions thats easy to describe but hard to perform!

    Rolf

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply