problem of insert multiple data into multiple table of sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • choong1990
    New Member
    • Jan 2012
    • 1

    problem of insert multiple data into multiple table of sql

    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,therefo re i hope inside my database,the data will look like
    Code:
    |-----------------------------------|
    |   RecordID  |  ItemID   |   Amount|
    |-----------------------------------|
    |      1      |     1     |    10   |
    |      1      |     2     |    100  |
    --------------------------------------
    and now what i get is...
    Code:
    |-----------------------------------|
    |   RecordID  |  ItemID   |   Amount|
    |-----------------------------------|
    |      1      |     1     |    10   |
    |      2      |     2     |    100  |
    --------------------------------------
    because i'm using store procedure and needed loop to store all "ItemID" into sql.

    Code:
    +------------+     +-----------------+     
    | 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.
  • C CSR
    New Member
    • Jan 2012
    • 144

    #2
    This looks kinda like a:

    For i = x to y

    Comment

    • C CSR
      New Member
      • Jan 2012
      • 144

      #3
      Sorry, got cut off. Repeat:

      for i = 1 to x
      for j = 1 to y
      next j
      next y

      Its called "nesting." The "i" represents the clientID and "j" is the number of entries for that clientID. This is just an example. Gracefully, its not a loop.

      Comment

      • C CSR
        New Member
        • Jan 2012
        • 144

        #4
        Correction, it is actually a loop :), but I don't see any way around it.

        Comment

        • PsychoCoder
          Recognized Expert Contributor
          • Jul 2010
          • 465

          #5
          This can technically be done without using a loop but it's going to be a lot more work on you. I suggest using a loop to accomplish this

          Comment

          • Èñìàèëëû
            Banned
            New Member
            • Jan 2012
            • 1

            #6
            íà bytes.com òóò áûëî ìíîãî êîììåíòîâ - êóäà âñå ïîäåâàëîñü? òàì áûëè è èíòåðåñíûå?

            Comment

            Working...