for Example
| PONumber |
Qty |
| P00001 | 50 |
| P00001 | 40 |
| P00001 | 30 |
| P00001 | 20 |
| P00001 | 10 |
in this example i want to get my last inserted record ( PONumber - P00001 & Qty -10) by PONumber
| PONumber |
Qty |
| P00001 | 50 |
| P00001 | 40 |
| P00001 | 30 |
| P00001 | 20 |
| P00001 | 10 |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 7, 2013, 8:07 PM EDT
hi,
you are performing bulk operation?
if no so you cannot find last inserted record you must have filed like id or created date from that you can find last inserted value. Id filed may auto Identity...
Select top 1 * from POTable where POnumber = 'P00001' order by Id desc
Select top 1 * from POTable where POnumber = 'P00001' order by createdDate desc
hope this will help you.
Kunal VaishyaRank #990 · 2K reputationPosted Jul 7, 2013, 8:17 PM EDT
Using this you can get last Primary Key which inserted last
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 7, 2013, 8:21 PM EDT
SELECT TOP 1 PONumber FROM tablename ORDER BY PONumber DESC
more details
http://www.aspdotnet-suresh.com/2012/06/query-to-get-last-inserted-record-id-in.html
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 7, 2013, 8:25 PM EDT
If your table does not have identity column or primary column then you can try like this
SELECT TOP 1 PONumber , Qty , row_number() over ( order by ( SELECT 2 ) ) AS ROWNUMBER FROM POInfo ORDER BY ROWNUMBER DESC
Regards,
Iftikar