If you are creating invoices by just using InvoiceLine inserts without using group items, run:
SP_LASTINSERTID invoiceline
and grab the TxnID and do:
select Top 1 TxnID, InvoiceLineTxnLineId, InvoiceLineSeqNo from InvoiceLine where TxnID='5D43-1197768681' order by InvoiceLineSeqNo Desc
Otherwise, if you do invoice group items you will need to do something like this:
select Top 1 TxnID, InvoiceLineTxnLineId, InvoiceLineSeqNo from invoiceline where TxnID='5D43-1197768681' and InvoiceLineTxnLineId is not null order by InvoiceLineSeqNo Desc
but if you are the only one creating invoices at the time, simply jump the gun by just doing:
select Top 1 TxnID, InvoiceLineTxnLineId, InvoiceLineSeqNo from invoiceline where InvoiceLineTxnLineId is not null order by TimeModified DESC, InvoiceLineSeqNo Desc
BTW: You can leave out the null test if you don't use Itemgroups. |