sql server - SQL INSERT INTO query copy 3 x times -
i have master table , i'd insert into table straight forward copy. want copy table 3 x times changing value of 1 x field called comp (short company). in master table field comp contains value master. i'd change value 3 x new companies a, b & c.
how & in query do this?
much appreciated assistance!
lets have following table values , 1 more table same schema called anothertable
create table mastertable( comp varchar(50), moredata varchar(200) ); and have 3 values:
declare @comp1 varchar(50) = 'acomp', @comp2 varchar(50) = 'bcomp', @comp3 varchar(50) = 'ccomp'; insert anothertable select @comp1, moredata mastertable union select @comp2, moredata mastertable union select @comp3, moredata mastertable now there still issues of primary key, clustered index. have identity in these tables or identifier. if tables huge need in 3 inserts
insert anothertable select @comp1, moredata mastertable; insert anothertable select @comp2, moredata mastertable; insert anothertable select @comp3, moredata mastertable;
Comments
Post a Comment