Fix for MS SQL group by