Fixed issue in SQL Server query