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)my result has 8 and 9, not 10 and 11.
>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)>>