Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Speed in results
Message
 
To
12/08/2008 13:01:31
Sonny Tabano
Trams Printwork, Inc.
Mabalacat, Philippines
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01338372
Message ID:
01338374
Views:
21
>Hi, what do you think on which of the following samples below would produce faster result? Or there's no difference at all?
>
>Total number of records in table is 500,000
>There are 10 records whose cv_no is = "00800".
>record numbers for the ten (10) cv_no="00800" is from recno(440,000 to 449,000 )
>
>lcDocNumb="00800"
>
>
>
>Sample No. 1
>
>Select CVdtl
>set order to CVnoacct
>=Seek(lcDocNumb)
>IF FOUND()
>   DO while CV_no=lcDocNumb .and. .not. EOF()
>          IIF .not. DELETED()
>                lnSLDBAmt  = lnSLDBAmt + SLDebit
>                lnSLCRAmt  = lnSLCRAmt + SLCredit
>                lnGLDBAmt  = lnGLDBAmt + GLDebit
>               lnGLCRAmt  = lnGLCRAmt + GLCredit
>         Endif
>         skip
>    enddo
>ENDIF
>
>
>Sample No. 2
>
>SELECT SUM(A.SLDebit) as lnSLDBAmt, SUM(SLCredit) as lnSLCRAmt, SUM(GLCredit) as lnGLCRAmt, SUM(GLDebit) as lnGLDBAmt;
>FROM CVdtl A WHERE A.CV_no=lcDocNumb .and. .not. DELETED() INTO CURSOR Temp1 GROUP BY A.CV_no
>
>
>Sample No. 3
>
>Select CVdtl
>set order to CVnoacct
>SCAN FOR CV_no=lcDocNumb
>        IF .not. DELETED()
>            lnSLDBAmt  = lnSLDBAmt + SLDebit
>            lnSLCRAmt  = lnSLCRAmt + SLCredit
>            lnGLDBAmt  = lnGLDBAmt + GLDebit
>            lnGLCRAmt  = lnGLCRAmt + GLCredit
>      Endif
>ENDSCAN
>
>
>
>Thanks
>
>Sonny

You should test it by yourself. Nobody can tell you what is the fastest just because nobody knows your table and what indexes you have.
But I would check these TWO possibilities:
SET DELETED ON

** 1.:
Select CVdtl
set order to CVnoacct
SEEK m.lcDocNumb
SCAN WHILE  CV_no = m.lcDocNumb
      lnSLDBAmt  = lnSLDBAmt + SLDebit
      lnSLCRAmt  = lnSLCRAmt + SLCredit
      lnGLDBAmt  = lnGLDBAmt + GLDebit
      lnGLCRAmt  = lnGLCRAmt + GLCredit
ENDSCAN

*** 2.
SYS(3054,12,[testSQL])
SELECT SUM(A.SLDebit) as lnSLDBAmt,;
        SUM(SLCredit) as lnSLCRAmt,;
        SUM(GLCredit) as lnGLCRAmt,;
        SUM(GLDebit) as lnGLDBAmt;
FROM CVdtl A;
WHERE A.CV_no=lcDocNumb ;
INTO CURSOR Temp1;
GROUP BY A.CV_no
SYS(3054,0)
MessageBox(TestSQL)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform