Feb 11
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Add the following code at the end of method add_limit_offset!(sql, options) in sqlserver_adapter.rb
if options[:order]
order_fields = options[:order].split(',').collect do |field|
column_name = field.split(" ")[0]
"#{column_name} AS #{column_name.gsub('.', '_')}"
end
sql.gsub!(/^\s*SELECT(\s+DISTINCT)(.*?) FROM/i, "SELECT\\1 \\2, #{order_fields.join(', ')} FROM")
end