bug fixed for mssql limit

This commit is contained in:
Lunny Xiao 2014-05-06 14:19:37 +08:00
parent beecda2e23
commit 9347c8ab3e
1 changed files with 8 additions and 2 deletions

View File

@ -996,7 +996,9 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
}
if statement.Engine.dialect.DBType() == core.MSSQL {
top = fmt.Sprintf(" TOP %d", statement.LimitN)
if statement.LimitN > 0 {
top = fmt.Sprintf(" TOP %d ", statement.LimitN)
}
if statement.Start > 0 {
var column string = "(id)"
if len(statement.RefTable.PKColumns()) == 0 {
@ -1019,7 +1021,11 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
a = fmt.Sprintf("SELECT %v%v%v%v%v", top, distinct, columnStr,
fromStr, whereStr)
if mssqlCondi != "" {
a += " AND " + mssqlCondi
if whereStr != "" {
a += " AND " + mssqlCondi
} else {
a += " WHERE " + mssqlCondi
}
}
if statement.GroupByStr != "" {