title: Execute very long statements in TSQL using sp_executesql
body: <p>I would like to execute dynamic SQL statements which are about 10,000 characters.</p>
  
  <p>When I use sp_executesql as below:</p>
  
  <pre><code>DECLARE @stmt varchar(MAX)
  
  SET @stmt = 'xxxxxxxx.................' which is about 10,000 characters
  
  EXEC sp_executesql @stmt
  </code></pre>
  
  <p>I got the following error</p>
  
  <pre><code>The character string that starts with '  select t1.e_reference xxxxxxxxxxx' is too long. Maximum length is 8000. 
  </code></pre>
  
  <p>As far as I know, we can use sp_executesql to execute very long statements, can't we?</p>
  
  <p>I am using SQL Server 2008, Enterprise Edition, 64 bit.</p>
  
  <p>How can I achieve this?  Thanks.</p>