Subject Re: [firebird-support] Insert from query, but changing one field?
Author Helen Borrie
At 01:02 PM 21/10/2003 -0700, you wrote:
>Here's my situation:
>
>I have a class enrollments table. It contains the student ID, the class
>ID, and some other things.
>
>What I want to do is take all of the enrollments (rows in this table), and
>copy them to all to another class. This would involve copying all of the
>enrollment records with a certain CLASSID back to the same table, but with
>a different CLASSID, leaving all of the other fields the same.
>
>So, I'm thinking of something like:
>
>insert into enrollments select * from enrollments where classid = 123
>
>However, this will make duplicate copies of the enrollment record, meaning
>that they'll still have classid 123. Somehow in the command, I need to
>change the CLASSID of the newly inserted rows to, say, 456.
>
>I want to do this with a single SQL command, not a SP. Is this possible?

Assuming you have a generator + trigger supplying the PK value, col1:

insert into enrollments (col2, col3, ...., classid, ....)
select col2, col3, ...., 456, ....
from enrollments
where classid <> 456

heLen