title: Dynamically insert data into a temp table with like as variable
body: <p>I am trying to dynamically insert data into a temp table passing like data as a variable:</p>
  
  <pre><code>DECLARE @data NVARCHAR(MAX)
  SET @data = 'INSERT INTO #coco  ' + '([' + @val + '])' + ' SELECT [USER_ID] FROM [dbo].[Sheet1$] WHERE [Standard_Name] LIKE ' + @val
  
  EXEC sp_executesql @data
  </code></pre>
  
  <p><code>@val</code> is a column name selected from table <code>Sheet1$</code> and few column name has space between them. While executing, I am getting error, like for column name "Acrobat Reader":</p>
  
  <blockquote>
    <p>Incorrect syntax near 'Acrobat'.</p>
  </blockquote>
  
  <p>Also if I am adding data using hardcoded one by one in a column its adding data to one column while other column its adding NULL.</p>
  
  <p>Any suggestion how I can overcome this?</p>