title: SQL Insert into … ( SELECT *, SCOPE_IDENTITY() FROM … )
body: <p>I created a stored procedure that should do 2 inserts in one</p>
  
  <p>First step I want to create a new entry per insert into.</p>
  
  <p>Second step I will catch the created Id from this entry</p>
  
  <p>Third step I want to copie multiple entries per select from one table and insert those to the same table with the Id</p>
  
  <pre><code>Create PROCEDURE dbo.Rolle_Copie
      @Id as int,
      @newId as int = 0,
      @Name AS nvarchar(50)
  AS
      INSERT INTO Rollen (RolleName) 
      VALUES (@Name)
  
      @newId = SCOPE_IDENTITY()
  
      INSERT INTO Berechtigung_Rolle (RefRolleId,RefBerechtigungId)
          SELECT   
             RefBerechtigungId, @newId 
          FROM     
             Berechtigung_Rolle 
          WHERE    
             RefRolleId = @Id
  
      RETURN
  </code></pre>
  
  <p>but I get an error </p>
  
  <blockquote>
    <p><em>Wrong syntax next to @newId</em></p>
  </blockquote>
  
  <p>Could somebody please enlight me what's wrong?</p>
  
  <p>Any advice is greatly appreciated</p>