fix query for MS-SQL