From 9347c8ab3e55da28f8a44e973acc913420ebf0b3 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 6 May 2014 14:19:37 +0800 Subject: [PATCH] bug fixed for mssql limit --- statement.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/statement.go b/statement.go index 5185c91e..f5c122cb 100644 --- a/statement.go +++ b/statement.go @@ -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 != "" {