title: How to write raw SQL with placeholder for AR SQL Server adapter?
body: <p>I have a complicated join condition with three interpolated values that are being double-quoted (as part of AR's quoting to avoid SQL injection attacks, I think).</p>
  
  <p>I've ready other questions saying that I can make use of <code>:sanitize_sql</code> or <code>:sanitize_sql_array</code> with <code>?</code> placeholders, but alas, those seem to be undefined with <a href="https://github.com/rails-sqlserver/activerecord-sqlserver-adapter" rel="nofollow"><code>activerecord-sqlserver-adapter</code></a>.</p>
  
  <p>So, my question is, how can I make this work with SQL server through ActiveRecord??</p>
  
  <hr>
  
  <pre><code>def self.with_active_deal_counts
    joins(&lt;&lt;-SQL.squish
      LEFT OUTER JOIN (
        SELECT [b].[merchant_id], COUNT(*) deal_count
        FROM   [tbl_deal] b
        WHERE deal_active = 1
          AND deal_archive = 2
          AND ( deal_end = '1900-01-01'
                OR deal_end &gt; '#{Time.now + Time.now.utc_offset - 1.day}')
          AND deal_start &lt;= '#{Time.now + Time.now.utc_offset}'
        GROUP BY [b].[merchant_id]
      ) a ON a.[merchant_id] = [tbl_merchant].[merchant_id]
      SQL
    ).select("tbl_merchant.*, a.deal_count")
  end
  </code></pre>
  
  <p>This yields </p>
  
  <pre><code>EXEC sp_executesql N'SELECT tbl_merchant.*, a.deal_count FROM [tbl_merchant] LEFT OUTER JOIN (
   SELECT [b].[merchant_id], COUNT(*) deal_count
   FROM [tbl_deal] b
   WHERE deal_active = 1
   AND deal_archive = 2
   AND ( deal_end = ''1900-01-01''
   OR deal_end &gt; ''2013-09-30 07:07:20 -0700'')
   AND deal_start &lt;= ''2013-10-01 07:07:20 -0700''
   GROUP BY [b].[merchant_id]
  ) a ON a.[merchant_id] = [tbl_merchant].[merchant_id]'
  </code></pre>
  
  <p>... which doesn't work because of the double-quoted values, eg. <code>''2013-09-30 07:07:20 -0700''</code></p>
  
  <p>Specifically, I get <code>Incorrect syntax near '1900'</code> (when running the query in SQL Management Studio.</p>