TOP X mssql limit clause must appear after DISTINCT if they are both present
authorRuss Tyndall <russ@acceleration.net>
Mon, 27 Jun 2011 18:48:27 +0000 (14:48 -0400)
committerNathan Bird <nathan@acceleration.net>
Mon, 27 Jun 2011 20:53:48 +0000 (16:53 -0400)
ChangeLog
sql/expressions.lisp

index aa4a5c551bc9d9fd004ed1c72cf98759a92fec79..62234226d200a35d786da67e350351b47d7ba247 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2011-06-27  Nathan Bird  <nathan@acceleration.net>
        * db-odbc/: memory management improvements: leak slower
+       * MSSQL: TOP + DISTINCT work together
 
 2011-06-20  Nathan Bird  <nathan@acceleration.net>
 
index c7236a454f56cb4c4c08a102c4ee61381c162996..c7fd033da646d6c0a17520a64f129f79fb37ad34 100644 (file)
 (defmethod output-sql ((expr sql-query-modifier-exp) database)
   (with-slots (modifier components)
       expr
-    (output-sql modifier database)
+    (%write-operator modifier database)
     (write-string " " *sql-stream*)
     (output-sql (car components) database)
     (when components
@@ -586,10 +586,6 @@ uninclusive, and the args from that keyword to the end."
     (when *in-subselect*
       (write-string "(" *sql-stream*))
     (write-string "SELECT " *sql-stream*)
-    (when (and limit (eql :mssql (database-underlying-type database)))
-      (write-string " TOP " *sql-stream*)
-      (output-sql limit database)
-      (write-string " " *sql-stream*))
     (when all
       (write-string " ALL " *sql-stream*))
     (when (and distinct (not all))
@@ -598,6 +594,10 @@ uninclusive, and the args from that keyword to the end."
         (write-string " ON " *sql-stream*)
         (output-sql distinct database)
         (write-char #\Space *sql-stream*)))
+    (when (and limit (eql :mssql (database-underlying-type database)))
+      (write-string " TOP " *sql-stream*)
+      (output-sql limit database)
+      (write-string " " *sql-stream*))
     (let ((*in-subselect* t))
       (output-sql (apply #'vector selections) database))
     (when from