Discussion:
insert two rows from one
(too old to reply)
mcnewsxp
2013-01-05 16:37:23 UTC
Permalink
i have a table that has tableid, consent1, batch1, consent2, batch2.
i want to insert into consents tableid, consent1, batch1 into one row and
tableid, consent2, batch2 into another row.
can this be done in one pass?
how to code this?
tia,
mcnewsxp
Bob Barrows
2013-01-05 18:16:25 UTC
Permalink
Post by mcnewsxp
i have a table that has tableid, consent1, batch1, consent2, batch2.
i want to insert into consents tableid, consent1, batch1 into one row
and tableid, consent2, batch2 into another row.
can this be done in one pass?
how to code this?
tia,
mcnewsxp
Why insert into a new table? Just create a view based on a union query:

create view ConsentsAndBatches AS
select tableid, consent1 as consent, batch1 as batch from table
union all
select tableid, consent2 as consent, batch2 as batch from table
mcnewsxp
2013-01-06 15:18:02 UTC
Permalink
Post by Bob Barrows
Post by mcnewsxp
i have a table that has tableid, consent1, batch1, consent2, batch2.
i want to insert into consents tableid, consent1, batch1 into one row
and tableid, consent2, batch2 into another row.
can this be done in one pass?
how to code this?
tia,
mcnewsxp
create view ConsentsAndBatches AS
select tableid, consent1 as consent, batch1 as batch from table
union all
select tableid, consent2 as consent, batch2 as batch from table
because this is a conversion from one system to another. table is an export from a system that is going away. that system only allows for flat file export.

thanks tho.
mcnewsxp
2013-01-06 18:47:04 UTC
Permalink
Post by mcnewsxp
Post by Bob Barrows
Post by mcnewsxp
i have a table that has tableid, consent1, batch1, consent2, batch2.
i want to insert into consents tableid, consent1, batch1 into one row
and tableid, consent2, batch2 into another row.
can this be done in one pass?
how to code this?
tia,
mcnewsxp
create view ConsentsAndBatches AS
select tableid, consent1 as consent, batch1 as batch from table
union all
select tableid, consent2 as consent, batch2 as batch from table
because this is a conversion from one system to another. table is an export from a system that is going away. that system only allows for flat file export.
thanks tho.
but your view example got me where i needed to be.
thanks.

Continue reading on narkive:
Loading...