title: How to execute a stored procedure after it is created?
body: <p>I'm trying to execute a stored procedure directly after its creation however it is not getting called. It looks like the stored procedure is not yet created during the execution call.</p>
  
  <p>Here is how the script looks like:</p>
  
  <pre><code>CREATE PROCEDURE sp_Transfer_RegionData
  AS
  BEGIN
      INSERT INTO Region (regionName)
      SELECT column1
      FROM openquery(ITDB, 'select * from db.table1')
  END
  
  EXEC sp_Transfer_RegionData
  </code></pre>
  
  <p>The script runs fine however the needed table is not populated. After replacing the execution part with:</p>
  
  <pre><code>IF OBJECT_ID('sp_Transfer_RegionData') IS NOT NULL
  begin
  
  exec [dbo].[sp_Transfer_RegionData]
  print 'tada'
  end
  </code></pre>
  
  <p>I could see that the stored procedure does not exist when it has to be executed. Couldn't find a solution for this in the internet...</p>
  
  <p>So how to make the SQL script run sync so that the stored procedure would already exist during the execution part?</p>