I am aiding Kathi Kellenberger with her new article. I wrote a solution that work fine for the small sample set in the article. Today I added the sample set with 176,000 rows.
This gives me strange results! The table is a heap. The code is attached.
When I run the code without OPTION(MAXDOP 1), I get a count ranging from 16112 and 16160. I have no idea why.
When I turn on OPTION(MAXDOP 1), I get the correct result of 16008 in almost all cases. In some cases I get a count of 16009.
Why is the count not stable? It doesn't matter if I put a clustered index on the table.