• Ok here we go...

    You'll need to build a tally table. Jeff Moden has an excellent article about tally tables here[/url].

    After you have a tally table, create a test table with test data: (or just plug in your own table I suppose)

    select top 10000 identity(int,1,1) as id, Dog

    into DogTable

    from

    (

    select 'dogcatdogdogbirdape' as Dog

    union all

    select 'fishbirdnotadogoopsthatwasadog'

    union all

    select 'caninecanislupisdomesticus'

    )x

    cross join

    (select sc1.name from master.dbo.syscolumns sc1

    cross join

    master.dbo.syscolumns sc2

    ) y

    Now for the solution:

    select id, count(id)

    from

    (

    select d.id, d.dog, substring(d.dog, case when t.N > len(d.dog) then len(d.dog) else t.n end, 3) as test, n as foundindex

    from dogtable d

    cross join

    tally t

    where t.n < (select max(len(dog)) from dogtable)

    and substring(d.dog, case when t.N > len(d.dog) then len(d.dog) else t.n end, 3) = 'dog'

    )x

    group by id

    Run the inner view if you just want a list of indexes of the tested string.

    This could be easily turned into a table valued function, just read the length of your input string into the last parameter of substring