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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Iftikar HussainPosted Jul 8, 2013, 12:25 AM
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
Sanjeeb LenkaPosted Jul 8, 2013, 12:21 AM
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
Kunal VaishyaPosted Jul 8, 2013, 12:17 AM
Using this you can get last Primary Key which inserted last
Jignesh TrivediPosted Jul 8, 2013, 12:07 AM
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.