Hi amar,
Refer below sample query.
SQL
DECLARE @tblTest AS TABLE(InvoiceNum NVARCHAR(MAX))
INSERT INTO @tblTest VALUES('INV001')
INSERT INTO @tblTest VALUES('INV002')
INSERT INTO @tblTest VALUES('INV003')
INSERT INTO @tblTest VALUES('INV004')
SELECT TOP 1 InvoiceNum FirstInvoice,
(SELECT TOP 1 * FROM @tblTest ORDER BY InvoiceNum DESC) LastInvoice
FROM @tblTest
Output
FirstInvoice |
LastInvoice |
INV001 |
INV004 |