Subject Re: Insert from query, but changing one field?
Author jbgilmartin
--- In firebird-support@yahoogroups.com, Joe Martinez <joe@j...>
wrote:
>
> >At 11:08 PM 21/10/2003 -0700, you wrote:
> >
> > > >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
> > >
> > >No, I don't have a generator/trigger generating the PK.
> >
> >You must be getting it from somewhere...if it's a composite of
something,
> >then you aren't going to get unique keys by dup'ing rows back into
the same
> >table, are you?
>
> Ah. Very good point. It looks like what you suggested above would
be the
> right solution, but I had completely forgotten about the PK. Oh
> well. Looks like I'll have to do this in code instead of a SQL
statement.
>
> Thanks,
> Joe

Maybe I missed something but to copy to another class you could take
Helen's SQL (though I changed it below) and limit it to the class you
want to copy and use the classid to copy to in the insert:

insert into enrollments (classid, studentid, ...)
select 456, studentit, ...
from enrollments
where classid = 123

This copies students from class 123 and puts them also in class 456
No code, just SQL. Did I miss something?