Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT to combine master and 2 child tables
Message
From
10/05/2004 21:57:42
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
SELECT to combine master and 2 child tables
Miscellaneous
Thread ID:
00902663
Message ID:
00902663
Views:
70
I've got a SELECT command that I'm using in ADO.NET in a VB.NET application. It works against SQL Server 2000, but I need it to work against VFP Free tables as well using the VFP OleDb driver. Here's the SQL:
SELECT h.pid_owner, h.ord_cod,
       (SELECT SUM(d.itm_prcus * d.qty_ord)
          FROM c:\qn\datatemp\qn_dtl d
          WHERE d.pid_owner = h.pid_owner
            AND d.ord_cod = h.ord_cod) AS OrderTotal,
       (SELECT SUM(i.itm_prcus * i.qty_sent)
          FROM c:\qn\datatemp\qn_inv i
          WHERE i.pid_owner = h.pid_owner
            AND i.ord_cod = h.ord_cod) AS InvoiceTotal
  FROM c:\qn\datatemp\qn_head h
  ORDER BY h.pid_owner, h.ord_cod
Basically, I have a master table (qn_head) and two child tables (qn_dtl and qn_inv). The child tables link to the master table on the fields pid_owner and ord_cod. I need one row for each row in qn_head with all the fields from qn_head, plus one field that sums the qn_dtl records for each qn_head record, plus one field that sums the qn_inv records for each qn_head record. For a given qn_head record there could be 0 or more qn_dtl record, and 0 or more qn_inv records. A given qn_head record may have a different number of qn_dtl records than it has qn_inv records.

VFP complains about invalid use of subquery with the above SQL, and I assume that's because VFP doesn't allow subqueries in the SELECT fields like I'm doing. If I only had one child table, this would be simple. But since I have 2 child tables, and I'm using free VFP tables, not a DBC (no views), and ADO.NET doesn't support dooing a SQL against a DataSet, I'm not sure how to get this to work.

-----
Lee Perkins
-----
Lee Perkins
TigerBase Technologies

"Lee is one that would plug his brain into the internet, if he could, and STILL scream for more" - Very good friend of Lee's
Next
Reply
Map
View

Click here to load this message in the networking platform