I'm having a multiple insert into..select statement as below. If u see, there is only one column value(Req_Attrname) is changing in all the three statements.Everything else is same including the where
conditions.
insert statement 1)
insert into details(repo_phyid,repo_type,repo_attrname,repo_Attrvalue
,Req_phyid,Req_type,Req_Attrname,Req_attrvalue)
select demo.phyid,'Complementary Item','Product Management Responsible',demo.attr_value,
tnr.phyid,'Complementary Item','**Product Manager**',demo.attr_value
From repo_Tnr Tnr,repo_Tnr_Attribute demo
Where Tnr.Phyid=demo.Phyid
And demo.Attr_Name='Product Management Responsible'
and tnr.type='Complementary Item'
insert statement 2)
insert into details(repo_phyid,repo_type,repo_attrname,repo_Attrvalue,
Req_phyid,Req_type,Req_Attrname,Req_attrvalue)
select demo.phyid,'Complementary Item','Product Management Responsible',demo.attr_value,
tnr.phyid,'Complementary Item','**Quality Manager**',demo.attr_value
From repo_Tnr Tnr,repo_Tnr_Attribute demo
Where Tnr.Phyid=demo.Phyid
And demo.Attr_Name='Product Management Responsible'
and tnr.type='Complementary Item'
insert statement 3)
insert into details(repo_phyid,repo_type,repo_attrname,repo_Attrvalue
,Req_phyid,Req_type,Req_Attrname,Req_attrvalue)
select demo.phyid,'Complementary Item','Product Management Responsible',demo.attr_value
,tnr.phyid,'Complementary Item',**'Depty Engineer**',demo.attr_value
From repo_Tnr Tnr,repo_Tnr_Attribute demo
Where Tnr.Phyid=demo.Phyid
And demo.Attr_Name='Product Management Responsible'
and tnr.type='Complementary Item'
What i'm trying here is, if the select returns me 20 rows, first i have to insert that 20 rows with Product Manager
as value for Req_attrname then i have to insert same 20 rows but with Quality Manager
and again with Deputy Engineer
. to accomplish this i'm using 3 insert statement. Like this i'm having 15 to 20 insert statement. Is there a way that can do it in single insert statement? it will help me to decrease the code and increase the readbility. Kindly provide an alternate solution.