October 23, 2002 at 7:41 pm
I have a table with two columns which currently has three rows
name1,VenA
name1,VenB
name1,VenC
what I want to do is duplicate these three rows with a different name,
eg result would be
name1,VenA
name1,VenB
name1,VenC
name2,VenA
name2,VenB
name2,VenC
I'm not sure how to use the use update and select statement to create the new rows.
real easy one
thanks
October 23, 2002 at 8:22 pm
This is the basics for 1 copy.
INSERT tblX (names, vens) SELECT 'name2', vens FROM tblX where name = 'name1'
Try a while loop sorta like this if you need to do a number of inserts
DECLARE @num int
DECLARE @name VARCHAR(7)
DECLARE @prename VARCHAR(7)
SET @num = 1
WHILE @num < 200
BEGIN
SET @num = @num + 1
SET @name = 'name' + cast(@num as varchar(3))
INSERT tblX (names, vens) SELECT @name, vens FROM tblX where name = 'name1'
END
This should give you an idea of where to go.
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
October 24, 2002 at 6:09 pm
Thanks
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply