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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:18:08+00:00 2026-05-28T06:18:08+00:00

How to insert multiple data into mssql without using loop? i’m developing a clinic

  • 0

How to insert multiple data into mssql without using loop?
i’m developing a clinic management system, while doctor may give few medicines to patient,therefore i hope inside my database,the data will look like

|-----------------------------------|
|   RecordID  |  ItemID   |   Amount|
|-----------------------------------|
|      1      |     1     |    10   |
|      1      |     2     |    100  |
--------------------------------------

and now what i get is…

|-----------------------------------|
|   RecordID  |  ItemID   |   Amount|
|-----------------------------------|
|      1      |     1     |    10   |
|      2      |     2     |    100  |
--------------------------------------

because i’m using store procedure and needed loop to store all “ItemID” into sql.

+------------+     +-----------------+     
| record      |     | record_items    |     
+------------+     +-----------------+    
|RecordID(PK)|  >  | RecordID (FK)   |  
|PatientID   |     | ItemID          |     
|Precription |     | Amount          |
|VisitDate   |     +-----------------+
+------------+ 

this is my 2 tables, i hope when storing data ,the recordID will not increase based on how many ItemID inserted.

ALTER PROCEDURE [dbo].[InsertPatientRecord]
    -- Add the parameters for the stored procedure here
    @PatientID INT,
    @Prescription VARCHAR(50),
    @VisitDate DATETIME,
    @ItemID INT,
    @Amount INT

AS

SET NOCOUNT On

    DECLARE @RecordID INT


        INSERT INTO record VALUES(@PatientID,@Prescription,@VisitDate)
        SET @RecordID=Scope_Identity()

    INSERT INTO record_item VALUES(@RecordID,@ItemID,@Amount)


RETURN

this is my stored procedure

  • 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-05-28T06:18:08+00:00Added an answer on May 28, 2026 at 6:18 am

    Since you will potentially have multiple record_items for each record, you need to have two stored procedures: one to write record (once) and one to write each of the record_items associated with the record.

    In order to make this work correctly, after writing record you will need to retrieve the recordid so that it can be passed to the stored procedure for record_items.

    Here is a rough outline for the stored procedures; the rest of the work I’ll leave up to you.

    One note: the RecordId is returned to the caller since it is an output parameter. This means that you will need to execute this procedure using a command (which you should be doing anyway) and will need to retrieve that value of this parameter after the stored procedure has been executed.

    Here is the record sp:

    ALTER PROCEDURE [dbo].[InsertPatientRecord]
        @RecordId      INT OUTPUT ,
        @PatientID    INT,
        @Prescription VARCHAR(50),
        @VisitDate    DATETIME
    AS
    
        INSERT INTO record VALUES(@PatientID,@Prescription,@VisitDate)
        SET @RecordID=Scope_Identity()
    

    and here is the record_items sp:

    ALTER PROCEDURE [dbo].[InsertPatientRecordItem]
        @RecordID     INT,
        @ItemID INT,
        @Amount INT
    
    AS
        INSERT INTO record_item VALUES(@RecordID,@ItemID,@Amount)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to insert data into multiple tables through a view in
i am using the dreamweaver cs4 insert into function to manage multiple forms on
In PHP, I want to insert into a database using data contained in a
Need help with PHP Mysql code to insert multiple select data into database. With
How do I escape data being inserted into a MySQL table without using an
I want to insert multiple rows of data into a MySQL database, but only
i'm trying to insert multiple data using a query, i've tried the implode function,
I was wondering how you can insert multiple rows into a MySQL database using
I want to insert multiple invisible watermarks into my JPEG pictures through C# code.
I know that I can insert multiple rows using a single statement, if I

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.