From c3276eb22108692b73ad35ce75809c52e6563daf Mon Sep 17 00:00:00 2001 From: Craig Peterson Date: Tue, 21 Feb 2017 14:23:01 -0700 Subject: [PATCH] fix issue with mssql NEXT option. Fixes #1205 --- dialects/mssql/mssql.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dialects/mssql/mssql.go b/dialects/mssql/mssql.go index ad2960ef..7c685c9f 100644 --- a/dialects/mssql/mssql.go +++ b/dialects/mssql/mssql.go @@ -129,16 +129,20 @@ func (s mssql) CurrentDatabase() (name string) { } func (mssql) LimitAndOffsetSQL(limit, offset interface{}) (sql string) { - if limit != nil { - if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit > 0 { - sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", parsedLimit) - } - } if offset != nil { if parsedOffset, err := strconv.ParseInt(fmt.Sprint(offset), 0, 0); err == nil && parsedOffset > 0 { sql += fmt.Sprintf(" OFFSET %d ROWS", parsedOffset) } } + if limit != nil { + if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit > 0 { + if sql == "" { + // add default zero offset + sql += " OFFSET 0 ROWS" + } + sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", parsedLimit) + } + } return }