title: sql- exceeding variable size in a exec?
body: <p>I inherited some partially complete sql code that I can't get to work.</p>
  
  <p>it accesses multiple databases, so it first searches for proper database using a userID number, then inserts that database name into a query. the part i'm having a problem with (extremely abbreviated) is...</p>
  
  <pre><code>DECLARE @sql AS VARCHAR(8000)  
      SET @sql = 'INSERT INTO ['+@DatabaseName+'].dbo.[customer]  
                    ( -- containing about 200 columns. )  
                  VALUES(...)'  
  PRINT @sql  
  EXEC(@sql)
  </code></pre>
  
  <p>i would get errors in the middle of a column name, sometimes saying it's expecting a parenthesis or quote. i started deleting white space so that, ie, [first name],[last name] were on the same line and not two different lines and that would get me a little further down the query. i don't have much more white spaces i can delete and i'm only just getting into the Values(...) portion of it. the weird thing is. i copy and pasted just the columns portion and put it into Word and it comes up as being only about 3,000 characters, including white space.</p>
  
  <p>am i missing something?<br>
  if it means anything, i'm running microsoft sql server 2005, and using the sql server management studio for editing</p>
  
  <p>thanks!</p>