Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:57:48+00:00 2026-06-17T18:57:48+00:00

I created a stored procedure that should do 2 inserts in one First step

  • 0

I created a stored procedure that should do 2 inserts in one

First step I want to create a new entry per insert into.

Second step I will catch the created Id from this entry

Third step I want to copie multiple entries per select from one table and insert those to the same table with the Id

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

but I get an error

Wrong syntax next to @newId

Could somebody please enlight me what’s wrong?

Any advice is greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:57:50+00:00Added an answer on June 17, 2026 at 6:57 pm

    don’t forget to use SET

    SET @newId = SCOPE_IDENTITY()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create stored procedure that call recursion function, each time it will
I want to create a stored procedure (on SQL Server 2005) that fetches a
I'm new to SQL and my first time to create a stored procedure. I
i need a experts advice that i should create separate stored procedure for every
I'm trying to create a stored procedure that will be used by a client
I would like to create a stored procedure with parameters that indicate which fields
i am writing stored procedures in MySQL that return values; CREATE PROCEDURE getCustomerById (id
I created a stored procedure. Following are the requirements: First match is done on
I have a stored procedure that inserts batches of millions of rows, emerging from
Good Evening All, I've created the following stored procedure: CREATE PROCEDURE AddQuote -- Add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.