INSERT - SELECT QUERY Help Needed.
-
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. ...
-
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. ...
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 listofpidsNever underestimate the power of human stupidity RAH