Subject | Re: Insert from query, but changing one field? |
---|---|
Author | jbgilmartin |
Post date | 2003-10-28T22:31:02Z |
--- In firebird-support@yahoogroups.com, Joe Martinez <joe@j...>
wrote:
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?
wrote:
>value, col1:
> >At 11:08 PM 21/10/2003 -0700, you wrote:
> >
> > > >Assuming you have a generator + trigger supplying the PK
> > > >something,
> > > >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
> >then you aren't going to get unique keys by dup'ing rows back intothe same
> >table, are you?be the
>
> Ah. Very good point. It looks like what you suggested above would
> right solution, but I had completely forgotten about the PK. Ohstatement.
> well. Looks like I'll have to do this in code instead of a SQL
>Maybe I missed something but to copy to another class you could take
> Thanks,
> Joe
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?