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 8311749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:54:54+00:00 2026-06-08T19:54:54+00:00

I need to add multiple rows in a table at once. Those rows have

  • 0

I need to add multiple rows in a table at once. Those rows have some field values in common.
I solved my problem using a cursor and this is the stored proc.

Does anyone have a better way of doing it?

    USE [MyDataBase]
    GO


    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[spAddDetailsBatch]
    (
    @IdOperTur UniqueIdentifier,
    @IdProd UniqueIdentifier,
    @Model Bit,
    @PrAd Decimal(18,2),
    @PrMe Decimal(18,2),
    @PoCo Decimal(5,2)
    )
    AS
    DECLARE @prpr_Id UniqueIdentifier
    DECLARE @IdCont UniqueIdentifier = NULL

    DECLARE CPr CURSOR FOR SELECT prpr_Id FROM trsx_PrPr WHERE (prod_Id = @IdProd)
    OPEN CPr

    FETCH NEXT FROM CPr INTO @prpr_Id
    WHILE @@Fetch_Status=0 BEGIN /*iterate through all records from cursor*/

     SET @IdCont = (SELECT cont_Id FROM trsx_Cont
                    WHERE  (prpr_Id = @prpr_Id) AND (optu_Id = @IdOperTur))

     IF @IdCont IS NULL
     BEGIN
      INSERT INTO trsx_Cont(cont_Id, prpr_Id, optu_Id, cont_Neto, cont_PrAd, cont_PrMe, cont_PoCo)
      VALUES (NEWID(), @prpr_Id, @IdOperTur, @Model, @PrAd, @PrMe, @PoCo)
     END

     FETCH NEXT FROM CPr INTO @prpr_Id
    END
   CLOSE CPr
   DEALLOCATE CPr
   RETURN

Thanks a lot.

  • 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-08T19:54:55+00:00Added an answer on June 8, 2026 at 7:54 pm

    How about something like this:

    insert into trsx_Cont(cont_Id, prpr_id, optu_Id, cont_Neto, cont_PrAd, cont_PrMe, cont_PoCo)
    select (newid(), trsx_PrPr.prpr_id, @IdOperTur, @Model, @PrAd, @PrMe, @PoCo)
    from trsx_PrPr
    where not exists(
        SELECT 1
        from trsx_Cont
        WHERE
            trsx_Cont.prpr_Id = trsx_PrPr.prpr_Id AND 
            trsx_Cont.optu_Id = @IdOperTur
    ) and
    trsx_PrPr.prod_id = @IdProd
    

    I haven’t tested this, and since it’s a little complex it may well not work as is, but you should be able to get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is the following. There are multiple rows that have non-unique identifiers: id
I have a tables of rows that exists in multiple databases. I will need
Greetings, Here is my problem. I need to get data from multiple rows and
I have a situation where I want to associate multiple values from one table
i need your help as the title says i have a problem inserting multiple
I need to add and delete class on an element having multiple classes: This
I need to add a CSS class to the TR (or multiple TR's) of
Hї! I have wrote test for my application. I need add item to database
Need to add two same name .csproj class libraries in my solution.Have two project
I have a form that once submitted some of its result are stored in

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.