SQL for threaded discussions #2 Does this not break when a single hash value in the postkey jumps over 10?
You are doing an ORDER BY on a varchar column with data that looks like this:
1
1.1
1.1.1
1.2.1
That's fine - no problems, until you reach something like this:
1.1.10.1
Which will, I believe, be inserted in the wrong order - i.e. in front of this record:
1.1.2.1
This is clearly a problem if you want to allow more than 10 direct replies to each parent post. Here is a more thorough solution I developed more than a year ago. Change your postkey columns to look like this:
001
001.001
001.001.001
001.002
With the above setup, our 1.1.10.1 will look like this:
001.001.010.001
and will order correctly, falling behind
001.001.002.001
as it should.
You will notice that this allows up to 1,000 direct replies under each parent. Every zero you add to each level will increase the number of possible direct replies by 10.
In ASP I use a config file to define the number of digits I want in each level. That way, if I want to allow 1 million direct replies to any parent, I set the digits param to 6 (000001 - 999999).
Thanks,
Kurt