title: SQLCMD create temp table
body: <p>I'm trying to get data from different SQL servers, and insert them into an temp table and afterwards process the data, all by using SQLCMD. </p>
  
  <p>I have the code for the process and it works perfect if you have only one database:</p>
  
  <pre><code>DECLARE @main table(Id int identity(1,1), Country nvarchar(5), [Message] nvarchar(200), Date datetime, pcname nvarchar(200))
  :connect Plant1
  use Plant1
  GO
  INSERT INTO @main 
  SELECT 'Plant1', Message, date, pcname FROM log.easyhmi WHERE DATE &gt; GETDATE() -15 AND [Message] LIKE 'MakeChangeOver | Verify changeover runinng processInstance Id: %'ORDER BY 1 DESC
  GO
  
  :connect Plant2
  use Plant2
  GO
  INSERT INTO @main
  SELECT 'Plant2', Message, date, pcname FROM log.easyhmi WHERE DATE &gt; GETDATE() -15 AND [Message] LIKE 'MakeChangeOver | Verify changeover runinng processInstance Id: %'ORDER BY 1 DESC
  GO
  
  :connect Plant3
  use Plant3
  GO
  INSERT INTO @main
  SELECT 'Plant3', Message, date, pcname FROM log.easyhmi WHERE DATE &gt; GETDATE() -15 AND [Message] LIKE 'MakeChangeOver | Verify changeover runinng processInstance Id: %'ORDER BY 1 DESC
  GO
  
  --Process data here......
  </code></pre>
  
  <p>But if I add more databases, then it can't find the <code>@main</code>.</p>
  
  <p>Is there a way that this can be done?</p>