Fix pagination on SQL Server 2000 with GROUP clause (Fix #367)

The pagination condition was added before the ORDER condition.
If there is a GROUP BY clause, the pagination was in the GROUP BY
instead of the WHERE clause. New approach is extracting each clause and
build a new proper query.