title: Microsoft SQL server: copy table from linked server to current database using a stored procedure
body: <p>I am using Microsoft SQL server. the following code works if run from a QUERY:</p>
  
  <pre><code>SELECT * 
  INTO mydatabase.dbo.atable 
  FROM linkedserver.sandbox.dbo.atable
  </code></pre>
  
  <p>but it does not if inserted into a stored procedure:</p>
  
  <pre><code>SET ANSI_NULLS ON  GO 
  SET QUOTED_IDENTIFIER ON  GO
  
  ALTER PROCEDURE dataMigration   
  AS  BEGIN   
   -- SET NOCOUNT ON added to prevent extra result sets from  
   -- interfering with SELECT statements.     
  
   SET NOCOUNT ON;
  
   -- Insert statements for procedure here     
  SELECT *     
  INTO mydatabase.dbo.atable  
  FROM linkedserver.sandbox.dbo.atable   
  
   END   
  GO
  </code></pre>
  
  <p>Command(s) completes successfully but no table is created into mydatabase. Sorry for the trivial question. I had a look at similar issues but i did not find a case similar to mine.</p>
  
  <p>Thank you for your help.</p>