Keshin
Keshin

Reputation: 29

How to use Insert into

I have data with field

TrxSeqCd     Name       Location
00001        Book       0001-A
00001        Book       0001-B
00001        Book       0001-C

I want duplicate the data but only location data is same, Field TrxSeqCd and Name will change with other codes and name

The data will be like this after i duplicate it

TrxSeqCd     Name       Location
00001        Book       0001-A
00001        Book       0001-B
00001        Book       0001-C
00002        Pen        0001-A
00002        Pen        0001-B
00002        Pen        0001-C

It's mean when i duplicate only location is same TrxSeqCd and Name will be change with what TrxSeqCd and Name That i want. Plz tell to me how to do it with Syntax Insert Into Note : the Table only 1 Table Not join with other table

Upvotes: 1

Views: 50

Answers (1)

Thorsten Kettner
Thorsten Kettner

Reputation: 95101

You need an insert select. The query to get the additional data is

select '00002' as TrxSeqCd, 'Pen' as Name, Location from mytable;

So the insert statement becomes

insert into mytable (TrxSeqCd, Name, Location)
select '00002' as TrxSeqCd,  'Pen' as Name, Location from mytable;

or shorter

insert into mytable (TrxSeqCd, Name, Location)
select '00002', 'Pen', Location from mytable;

Upvotes: 1

Related Questions