Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Received / Outgoing Product
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01210081
Message ID:
01211730
Views:
11
Hi Cecil,
Maybe I'm missing something but why do you need second quantity field and JOIN to the Customer table in the subselects?
* Yours
         (SELECT ;
               si.Cust, ;
               SUM(si.StandsIn) As QtyIn, ;
               000000 As QtyOut ;
            FROM ;
               Customer cs ;
                  INNER JOIN StandsIn si ;
                  ON cs.custno = si.cust ;
            WHERE ;
               BETWEEN(DateIn, .dFrom, .dThru) ;
            GROUP BY 1 ) ;
* Seems should be 
         (SELECT ;
               si.Cust, ;
               SUM(si.StandsIn) As QtyIn ;
            FROM ;
                 StandsIn si ;
            WHERE ;
               BETWEEN(DateIn, .dFrom, .dThru) ;
            GROUP BY 1 ) ;
>
>The following is what I ended up with as a Final Summary Report SQL
>Statement, pretty much based on what you and others advised me. I learned a
>bit of useful information through this exercise. I found that we had
>duplicate Customer Numbers, which produced doubled results. I cleaned up the
>duplicated Customer Numbers (CustNo) and found that some names had changed,
>etc. The clean-up was necessary to get correct results.
>
>I'd like to thank you, Naomi, Zakaria, Carlos, Rich and Beth for hanging in
>there with me. The SQL coding does not come naturally to me, but I am
>learning by experience. I am very much grateful for all of your help. :)
>
>The final SQL code:
>
>WITH ThisForm
>   * Have to set up two differents sets of date variables, since
>   * one set is DATE data type and the other set is STRING data type.
>   .dFrom=.txtStartdate.Value	&& Used in report form.
>   .dThru=.txtEndDate.Value	&& Used in report form.
>   lcStartDate=DTOC(.txtStartdate.Value)
>   lcStartDate=SUBSTR(lcStartDate,7,4) + ;
>      LEFT(lcStartDate,2) + ;
>      SUBSTR(lcStartDate,4,2)
>   lcEndDate=DTOC(.txtEndDate.Value)
>   lcEndDate=SUBSTR(lcEndDate,7,4) + ;
>      LEFT(lcEndDate,2) + ;
>      SUBSTR(lcEndDate,4,2)
>   SELECT ;
>         cs.custno, ;
>         cs.customer, ;
>         NVL(si1.QtyIn, 000000) As QtyIn, ;
>         NVL(so1.QtyOut, 0000000) As QtyOut, ;
>         NVL(si1.QtyIn, 0000000) - NVL(so1.QtyOut,0) As QtyDiff ;
>      FROM ;
>         customer cs ;
>      LEFT JOIN ;
>         (SELECT ;
>               si.Cust, ;
>               SUM(si.StandsIn) As QtyIn, ;
>               000000 As QtyOut ;
>            FROM ;
>               Customer cs ;
>                  INNER JOIN StandsIn si ;
>                  ON cs.custno = si.cust ;
>            WHERE ;
>               BETWEEN(DateIn, .dFrom, .dThru) ;
>            GROUP BY 1 ) ;
>         si1 ON si1.cust = cs.custno ;
>         LEFT JOIN ;
>         (SELECT ;
>               so.Cust, ;
>               SUM(so.SerialCnt) As QtyOut, ;
>               000000 As QtyIn ;
>            FROM ;
>               customer cs ;
>                  INNER JOIN Stands_Out so ;
>                  ON so.cust = cs.custno ;
>            WHERE ;
>               BETWEEN(date, lcStartDate, lcEndDate) ;
>            GROUP BY 1 );
>         so1 ON so1.cust = cs.custno ;
>      ORDER BY ;
>         cs.custno ;
>      INTO CURSOR final
>		
>   REPORT FORM Stands_Summary PREVIEW
>   WAIT WINDOW NOWAIT "Exporting File to G:\STANDS_SUMMARY_" + DTOC(DATE()) + ".XLS"
>   lcStringDate=DTOC(DATE())
>   lcMonth=LEFT(lcStringDate,2)
>   lcDate=SUBSTR(lcStringDate, 4, 2)
>   lcYear=SUBSTR(lcStringDate, 7, 4)
>   lcMMDDYYYYDate=lcMonth + lcDate + lcYear
>   COPY TO "G:\STANDS_SUMMARY_" + lcMMDDYYYYDate + ".XLS" TYPE XL5
>   SELECT FINAL
>   USE
>   lcMessageText="Stands Summary EXCEL file has been created on G:\"
>   lcTitleBarText="Stands_Summary" + lcMMDDYYYYDate + ".XLS"
>   MESSAGEBOX(lcMessageText, 0+64, lcTitleBarText)
>ENDWITH
>
>
>>Try
>
>SELECT ;
>            cs.CustNo, ;
>            cs.Customer, ;
>            NVL(QtyIn, 000000), ;
>            NVL(QtyOut, 000000), ;
>            NVL(QtyIn, 000000)-NVL(QtyOut, 000000) As QtyDiff ;
>         FROM Customer cs ;
>         LEFT JOIN (SELECT cust, SUM(StandsIn) FROM StandsIn AS QtyIn GROUP BY 1) si ON si.cust = cs.custno ;
>         LEFT JOIN (SELECT cust, SUM(SerialCnt) FROM Stands_Out AS QtyOut GROUP BY 1) so ON so.cust = cs.custno ;
>         ORDER BY ;
>            cs.Customer
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform