HHH-7041: Fix for messing up DISTINCT clause

This commit is contained in:
George Gastaldi 2012-02-08 18:14:49 -02:00 committed by Hardy Ferentschik
parent 608c2fadc8
commit 0ada357889
1 changed files with 2 additions and 1 deletions

View File

@ -149,7 +149,8 @@ public class SQLServer2005Dialect extends SQLServerDialect {
*/
protected static void replaceDistinctWithGroupBy(StringBuilder sql) {
int distinctIndex = sql.indexOf( DISTINCT );
if ( distinctIndex > 0 ) {
int selectEndIndex = sql.indexOf( FROM );
if (distinctIndex > 0 && distinctIndex < selectEndIndex) {
sql.delete( distinctIndex, distinctIndex + DISTINCT.length() + 1 );
sql.append( " group by" ).append( getSelectFieldsWithoutAliases( sql ) );
}