Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. INSERT - SELECT QUERY Help Needed.

INSERT - SELECT QUERY Help Needed.

Scheduled Pinned Locked Moved Database
csharpquestionasp-netdatabasehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    codingrocks
    wrote on last edited by
    #1

    I have the following tables. Table SS SID SNAME == ===== 1 AAA 2 BBB 3 CCC Table PP PID PNAME == ===== 1 Phase1 2 Phase2 3 Phase3 Third table (COMP) data may look like the following. ID SID PID == === === 1 1 1 2 1 2 3 1 3 4 2 1 5 2 2 ID here in third table is autoincrement. I need to insert a new record in SS table and it can have mapping to many Phases in PP table. So I want to write a INSERT INTO COMP (col1,col2) SELECT (col1,col2) FROM table... So ultimately new records needs to be inserted into the last table with a SID map and different PID. How can I accomplish the same? Thanks in advance.

    CodingRocks ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...

    M 1 Reply Last reply
    0
    • C codingrocks

      I have the following tables. Table SS SID SNAME == ===== 1 AAA 2 BBB 3 CCC Table PP PID PNAME == ===== 1 Phase1 2 Phase2 3 Phase3 Third table (COMP) data may look like the following. ID SID PID == === === 1 1 1 2 1 2 3 1 3 4 2 1 5 2 2 ID here in third table is autoincrement. I need to insert a new record in SS table and it can have mapping to many Phases in PP table. So I want to write a INSERT INTO COMP (col1,col2) SELECT (col1,col2) FROM table... So ultimately new records needs to be inserted into the last table with a SID map and different PID. How can I accomplish the same? Thanks in advance.

      CodingRocks ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Assuming you have a list of PIDs you want inserted you require 3 statemants,

      Declare @NewID int

      Insert SS (fields).Values

      Set @NewID = scope_identity()

      insert Comp(SID,PID)
      Select @NewID, PID from listofpids

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups