Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

multiple insert scope_identity

$
0
0

Hi.

I have to insert several records in a table called detallelibrobancos and by each one create another record in table detalleconciliacion.

If for example I insert a record in detallelibrobanco and it gives me the identity 20. This identity 20 must be inserted in detalleconciliacion in the field iddetallelibrobanco. Then If I insert another record in detallelibrobanco and it gives me the identity 21, This identity 21 must be inserted in detalleconciliacion in the field iddetallelibrobanco.

How can I do?

Thanks.

--Insercion de los movimientos
            DECLARE @IdDetalleLibroBanco INT
            INSERT  INTO Tesoreria.DetalleLibroBancos
                    ( IdLibroBanco ,
                      IdOpBancaria ,
                    )
                    SELECT  @IdLibroBanco ,
                            IDOPBANCARIA from test) )
            SELECT  @IdDetalleLibroBanco = SCOPE_IDENTITY()
            --Insercion en Tesoreria.DetalleConciliacion    
            INSERT  INTO Tesoreria.DetalleConciliacion
                    ( IdOpBancaria ,
                      IdDetalleLibroBanco 
                    )
            VALUES  (  IdOpBancaria 
                      @IdDetalleLibroBanco 
                    )   



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>