-
I want to make an insert into a table,taking the last value of a primary key from other table.How can I make it?
Insert Into HistSolicitudes(Idsolicitud,Estado,referencia,asunto,usuario)
Values ( Idsolicitud,Estado,referencia,asunto,usuario);
Idsolicitud is a foreign key,so I want to take the value from the "mother" table,and the last value from that primary key(in the other table...)
Thanks
-
May this be correct?:
Insert Into HistSolicitudes(Idsolicitud,Estado,referencia,asunto,usuario)
Values (SQ_SOLICITUDES.NextVal , 5 , ' histreferencia ' , ' histasunto ' , ' usuario ');
-
I think the best way is:
Select SQ_SOLICITUDES.Nextval into identificador from solicitudes;
Insert Into HistSolicitudes(Idsolicitud,Estado,referencia,asunto,usuario)
Values ( identificador ,' histestado ',' histreferencia ','histasunto ','usuario ');
-
I presume you have just inserted a row into Solicitudes using a sequence generated key. What you need is:
-- insert row into solicitues
Select SQ_SOLICITUDES.currval into identificador from solicitudes;
Insert Into HistSolicitudes(Idsolicitud,Estado,referencia,asunto,usuario)
Values ( identificador ,' histestado ',' histreferencia ','histasunto ','usuario ');
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|