Select the rows that just inserted

后端 未结 3 1266
抹茶落季
抹茶落季 2021-01-04 18:42

How can I retrieve the row just inserted?

INSERT INTO LETTRE_VOIT
select rsVoit.NOID, NO_ORDRE, rsOrdre.CODE_DEST, rsOrdre.MODAL_MODE, rsOrdre.MODAL_PORT,
CA         


        
相关标签:
3条回答
  • 2021-01-04 19:15

    If you are using SQL Server

    And you know how many row inserted then go through

    SELECT top 2 * FROM LETTRE_VOIT order by primaryKeyId desc
    

    put the number of row inserted at place of 2.

    It may be help you, If you know the number of inserted rows, and then you can provide the numbers with top keyword

    0 讨论(0)
  • 2021-01-04 19:19

    How about saving the records in a variable before inserting them or adding a date field and retrieve them by date?

    0 讨论(0)
  • 2021-01-04 19:21

    I'm not 100% sure what exactly you want back.... but SQL Server has an OUTPUT clause that can output stuff from INSERT and UPDATE and DELETE statements:

    INSERT INTO dbo.YourTable(col1, col2, ..., colN)
    OUTPUT Inserted.Col1, Inserted.IDCol, Inserted.Col17
    VALUES(val1, val2, ...., valN)
    

    Here, you're inserting values and the inserted values for the IDCol (e.g. an INT IDENTITY column), Col1 and Col17.

    If just getting back the results into your grid in Mgmt Studio is good enough - then use the OUTPUT clause! Read more about the OUTPUT clause on Books Online

    0 讨论(0)
提交回复
热议问题