Copy of mssql_backend from Trac hacks adapted for Trac 1.1.3-dev.
Now better handling of certain queries.