Is “SELECT TOP 0” a bug with MS SQL database?

The problem is not with the “select top 0”, but the way the query is changed behind the scenes. Even if you change it to “select * from…”, it will break.

I managed to get this working by going to “wp-includes\query.php” file, and then removing the $limits variable from the query. This is not the best way to fix the problem, but will get the site working. It looks like the $limits is breaking the query, and the ‘row offset’ of SQL server is different to MySql. I don’t know to much about how it all works, but I managed to get my installation working.

In the query.php file…

Find this line:

$this->request = ” SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits”;

change to:

$this->request = ” SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby”;

This solution will only work while you still use the your current version of WP.