Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Received / Outgoing Product
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01210081
Message ID:
01211491
Vues:
16
>Okay, what makes this a little difficult is that in one table, the date used is of data type DATE, whereas in another table it is a string only data type.
>
>I have created two separate SQL statements which are both producing correct results now; I need to put them together into one SQL statement in order to combine the fields and be able to subtract QtyOut from QtyIn for the Wire Stands. The code for the 2 separate SQL statements follows:
>
>
>WITH ThisForm
>	.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 ;
>			si.cust, ;
>			cs.customer, ;
>			SUM(si.StandsIn) As QtyIn, ;
>			000000 As QtyOut ;
>		FROM ;
>			STANDSIN si, ;
>			Customer cs ;
>		WHERE ;
>			BETWEEN(datein, .dFrom, .dThru) AND ;
>			si.cust = cs.custno ;
>		GROUP BY ;
>			si.Cust, ;
>			cs.customer ;
>		ORDER BY cs.Customer ;
>		INTO TABLE C:\si
>	
>	SELECT ;
>			so.cust, ;
>			cs.customer, ;
>			SUM(so.serialcnt) As QtyOut, ;
>			000000 As QtyIn ;
>		FROM ;
>			Stands_Out so, ;
>			Customer cs ;
>		WHERE ;
>			BETWEEN(date, lcStartDate, lcEndDate) AND ;
>			so.cust = cs.custno ;
>		GROUP BY ;
>			so.cust, ;
>			cs.customer ;
>		ORDER BY ;
>			cs.customer ;
>		INTO TABLE c:\so
>
>
>Each of these above SQL statements is now producing correct results. As I said above, I now need to combine these two statements. I am concerned as to how to combine them when the DATE data types are diffeeent.

Same as it already was suggested:
select cust.Customer, ;
       cast(nvl(si1.QtyIn,0) as N(10,2)) as QtyIn, ;
       cast(nvl(so1.QtyOut,0) as N(10,2)) as QtyOut, ;
       cast(nvl(si1.QtyIn,0) - nvl(so1.QtyOut,0) as N(10,2)) as nDiffer ;
       from Customer ;
       left join ;
      (SELECT ;
>			si.cust, ;
>			cs.customer, ;
>			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 ;
>			si.Cust, ;
>			cs.customer ;
>		ORDER BY cs.Customer ) si1 ;
                  on Customer.CustNo = si1.Cust ;
>	LEFT JOIN ;
>	(SELECT ;
>			so.cust, ;
>			cs.customer, ;
>			SUM(so.serialcnt) As QtyOut, ;
>			000000 As QtyIn ;
>		FROM Customer cs ;
                  INNER JOIN Stands_Out so ;
                  on cs.custno = so.cust ;
>		WHERE ;
>			BETWEEN(date, lcStartDate, lcEndDate) ;
>		GROUP BY ;
>			so.cust, ;
>			cs.customer ;
>		ORDER BY ;
>			cs.customer) so1 ;
                  ON customer.CustNo = so1.Cust ;
                  into cursor curFinal
Though I'm not 100% certain that you need to join with customer in the inner selects. You may try to go out without them.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform