Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

insert, column name from select

0 views
Skip to first unread message

Julien Mills

unread,
Nov 6, 2009, 9:12:27 AM11/6/09
to
Hi all,

This is what I want to do, not sure if
it is possible:

I'd like to run an insert where the column
names inserted into are based on the results
of the query, like this:

create table DETEMP
(product,
name,
quantity,
DE1,
DE2,
DE3);

insert into DETEMP
(product, name, quantity, columnname)
select product,
name,
quantity,
columnname
from SALESDETAIL;

Essentially I want to insert into either DE1, DE2, DE3
depending on the value of the columname column in SALESDETAIL.
Does anyone know of a good way to handle this?
I hope I'm explaining this clearly.

Thanks,

Julien

Captain Paralytic

unread,
Nov 6, 2009, 9:18:15 AM11/6/09
to

What do you want to insert into DE1, DE2 or DE3?
You are putting;
product->product
name->name
quantity->quantity
but you haven't explained what it is you want to put into the column
referenced by columname???

Peter H. Coffin

unread,
Nov 6, 2009, 10:04:08 AM11/6/09
to

Probably ought to put DE1, DE2, and DE3 out in their own table, linking
back to DETEMP via foreign key constraint, especially if your products
may have a variable number of DEn values.

--
79. If my doomsday device happens to come with a reverse switch, as soon as it
has been employed it will be melted down and made into limited-edition
commemorative coins.
--Peter Anspach's list of things to do as an Evil Overlord

0 new messages