>I just found out that in SQL Server, the WHERE clause has to be before the ORDER clause. Can someone confirms me that? If yes, is there a setting that affect that? It is not a big problem for me to adjust the code to support that however.
Yes, SQL Server is picky about the order of the clauses. It expects them in the order shown in BOL
SELECT select_list
FROM table_source
WHERE search_condition
GROUP BY group_by_expression
HAVING search_condition
ORDER BY order_expression
--sb--