diff --git a/lib/active_record/connection_adapters/sqlserver_adapter.rb b/lib/active_record/connection_adapters/sqlserver_adapter.rb
index <HASH>..<HASH> 100644
--- a/lib/active_record/connection_adapters/sqlserver_adapter.rb
+++ b/lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -627,7 +627,7 @@ module ActiveRecord
         def repair_special_columns(sql)
           special_cols = get_special_columns(get_table_name(sql))
           for col in special_cols.to_a
-            sql.gsub!(Regexp.new(" #{col.to_s} = "), " #{col.to_s} LIKE ")
+            sql.gsub!(/((\.|\s|\()\[?#{col.to_s}\]?)\s?=\s?/, '\1 LIKE ')
             sql.gsub!(/ORDER BY #{col.to_s}/i, '')
           end
           sql
Making the repair_special_columns method a little stronger.

It's not clear that this "fix the SQL via regexp" approach is super sustainable.  Not very sure how well we can cope with the ORDER BY clauses.  Also it's possible we've missed out on a bunch of ways that sql could be formatted.