CREATE CURSOR c_Test; >(iSaleid i,; >cInvoiceNo c(11),; >cDesc C(10)) > >FOR i = 1 TO 11 > INSERT INTO c_Test (iSaleid, cInvoiceNo, cDesc) VALUES (i, TRANSFORM(i), TRANSFORM(i)) >ENDFOR > >SET ANSI ON > >SELECT c_Test.*; > FROM c_Test ; > WHERE iSaleid in (SELECT TOP 2 isaleid FROM c_Test ORDER BY cInvoiceNo desc) > >SET ANSI OFF > >SELECT c_Test.*; > FROM c_Test ; > WHERE iSaleid in (SELECT TOP 2 isaleid FROM c_Test ORDER BY cInvoiceNo desc)>
>>SET ANSI ON >>SELECT Sales.* ; >> FROM Sales ; >> WHERE iSaleID IN (SELECT TOP 2 iSaleid FROM Sales ORDER BY cInvoiceNo DESC) >>>>
SELECT Sales.* ; >>> FROM Sales ; >>> WHERE iSaleID IN (SELECT TOP 2 iSaleid FROM Sales ORDER BY cInvoiceNo DESC)>>>
SELECT Sales.* ; >>> FROM Sales ; >>> WHERE iSaleID IN (SELECT TOP 2 iSaleid FROM Sales ORDER BY PADL(cInvoiceNo, 11) DESC)>>>
SELECT Sales.*; FROM Sales; INNER JOIN (SELECT TOP 2 iSaleid, PADL(iSaleid,11) AS Tst; FROM Sales; ORDER BY 2 DESC) Tbl1; ON Sales.iSaleid == Tbl1.iSaleid(not tested)