Deparsing query having DISTINCT and TOP

This is a proposal for a fix for SQL Server queries having TOP and DISTINCT clauses.
SQL Server requires to have the DISTINCT clause first.
See http://msdn.microsoft.com/en-gb/library/ms132161(v=sql.100).aspx

I only tested for SQL Server because I think that only SQL Server accepts the TOP clause.