From 524c3633158ec00787dbbb94905b16f0cb38fdad Mon Sep 17 00:00:00 2001 From: misiurev Date: Mon, 7 May 2018 13:34:14 -0400 Subject: [PATCH 1/2] union with limit on first page --- sql_server/pyodbc/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql_server/pyodbc/compiler.py b/sql_server/pyodbc/compiler.py index 8f70cd69..208b681a 100644 --- a/sql_server/pyodbc/compiler.py +++ b/sql_server/pyodbc/compiler.py @@ -241,7 +241,7 @@ def as_sql(self, with_limits=True, with_col_aliases=False): # SQL Server requires the backend-specific emulation (2008 or earlier) # or an offset clause (2012 or newer) for offsetting - if do_offset: + if do_offset or (combinator and high_mark): if do_offset_emulation: # Construct the final SQL clause, using the initial select SQL # obtained above. From b53282ff9adb910cb6542e856b59b8dbfb65dcf2 Mon Sep 17 00:00:00 2001 From: misiurev Date: Mon, 7 May 2018 13:38:57 -0400 Subject: [PATCH 2/2] union with limit on first page --- sql_server/pyodbc/compiler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sql_server/pyodbc/compiler.py b/sql_server/pyodbc/compiler.py index 208b681a..def2e13e 100644 --- a/sql_server/pyodbc/compiler.py +++ b/sql_server/pyodbc/compiler.py @@ -241,6 +241,7 @@ def as_sql(self, with_limits=True, with_col_aliases=False): # SQL Server requires the backend-specific emulation (2008 or earlier) # or an offset clause (2012 or newer) for offsetting + # Additionally support "limit" for queries that use UNION, EXCEPT if do_offset or (combinator and high_mark): if do_offset_emulation: # Construct the final SQL clause, using the initial select SQL