title: openquery passing date parameter conversion failed
body: <p>Created the following stored procedure to create a dataset within SSRS.  But when I run the query in SSRS I get the conversion failed error when converting date from character string.  I'm sure it's a syntax or variable issue.  Any ideas?</p>
  
  <pre><code>   ALTER PROCEDURE [dbo].[usp_r_pcdh_counts]
       @START datetime,
       @END datetime
         AS
         BEGIN
         SET NOCOUNT ON;
     DECLARE @START1 datetime= @START 
     DECLARE @END1 datetime = @END
     DECLARE @sql nvarchar (4000)
     SET @sql= 'SELECT *
     FROM OPENQUERY(MR_UNI,''select 
                  count(case when event_audit_type_key in ("1346","1038") then 1 else null end) as outsuccessful,
                  count(case when event_audit_type_key = "1531" then 1 else null end) as outunsuccessful,
                  count( case when event_audit_type_key in ("1040") then 1 else null end) as outdocsfound,
                  count( case when event_audit_type_key in ("1532") then 1 else null end) as outdocsnotfound,
                  count( case when event_audit_type_key in ("1042") then 1 else null end) as outdocsretrieved,
                  count( case when event_audit_type_key in ("1580") then 1 else null end) as outdocsnotretrieved,
                  count( case when event_audit_type_key in ("1048") then 1 else null end) as insuccess,
                  count( case when event_audit_type_key in ("1048") and success_code = "12"  then 1 else null end) as infailure,
                  count( case when event_audit_type_key in ("1050") then 1 else null end) as indocsretrieved
              from public.event_audit ea
              where ea.event_date &gt;= convert(date,''''' + @START1+ ''''', 110)
                      and ea.event_date &lt; convert(date, '''''+ @END1+ ''''', 110)
                      AND event_audit_key &gt;= (SELECT MAX(event_audit_key) - 100 
                           FROM reports.event_audit_index 
                           WHERE event_date &lt;= convert(date, '''''+ @START1+ ''''', 110))
                      AND event_audit_key &lt;= (SELECT MIN(event_audit_key) + 100 
                           FROM reports.event_audit_index 
                            WHERE event_date &gt;= convert(date, '''''+ @END1+''''', 110))'')'
      EXEC @sql
      END
  </code></pre>