Insert
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Insert

  1. #1
    Join Date
    Jan 2002
    Posts
    152
    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


  2. #2
    Join Date
    Jan 2002
    Posts
    152
    May this be correct?:

    Insert Into HistSolicitudes(Idsolicitud,Estado,referencia,asunto,usuario)
    Values (SQ_SOLICITUDES.NextVal , 5 , ' histreferencia ' , ' histasunto ' , ' usuario ');

  3. #3
    Join Date
    Jan 2002
    Posts
    152
    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 ');



  4. #4
    Join Date
    Nov 2001
    Location
    UK
    Posts
    152
    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
  •  



Click Here to Expand Forum to Full Width