diff --git a/dialect_common.go b/dialect_common.go index 333b0b45..a1c8ff5c 100644 --- a/dialect_common.go +++ b/dialect_common.go @@ -109,11 +109,13 @@ func (s commonDialect) currentDatabase() (name string) { } func (commonDialect) LimitAndOffsetSQL(limit, offset int) (sql string) { - if limit >= 0 { - sql += fmt.Sprintf(" LIMIT %d", limit) - } - if offset >= 0 { - sql += fmt.Sprintf(" OFFSET %d", offset) + if limit > 0 || offset > 0 { + if limit >= 0 { + sql += fmt.Sprintf(" LIMIT %d", limit) + } + if offset >= 0 { + sql += fmt.Sprintf(" OFFSET %d", offset) + } } return } diff --git a/dialect_mssql.go b/dialect_mssql.go index 63b46e9e..2ecc27cc 100644 --- a/dialect_mssql.go +++ b/dialect_mssql.go @@ -96,18 +96,16 @@ func (s mssql) currentDatabase() (name string) { } func (mssql) LimitAndOffsetSQL(limit, offset int) (sql string) { - if limit < 0 && offset < 0 { - return - } + if limit > 0 || offset > 0 { + if offset < 0 { + offset = 0 + } - if offset < 0 { - offset = 0 - } + sql += fmt.Sprintf(" OFFSET %d ROWS", offset) - sql += fmt.Sprintf(" OFFSET %d ROWS", offset) - - if limit >= 0 { - sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", limit) + if limit >= 0 { + sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", limit) + } } return }