Article ID: 196968
Article Last Modified on 3/14/2005
SHAPE {SELECT * FROM Employees WHERE LastName='Davolio'}
APPEND ({SELECT * FROM Orders} AS EmpOrders
RELATE EmployeeID TO EmployeeID)
the SHAPE provider does not know how to modify the second SELECT statement
in order to restrict the records to just Nancy Davolio. In fact, it does
not even know that the parent records are being restricted at all. Because
of this, all Orders for all employees are read into the local buffer.
SHAPE {SELECT * FROM Employees WHERE LastName='Davolio'}
APPEND ({SELECT * FROM Orders WHERE EmployeeID = ?} AS EmpOrders
RELATE EmployeeID TO PARAMETER 0)
In this case, the SHAPE provider reads the parent records first. It then
queries for the child records as each parent record is visited. If the
parent recordset contains a single record, then this is very efficient. If
it contains more records, then a separate query to retrieve child records
will be executed for each parent record visited. The child records are
cached, so this does not add overhead if parent records are visited
multiple times.
SHAPE {SELECT * FROM Employees WHERE LastName='Davolio'}
APPEND ({SELECT Orders.*
FROM Orders INNER JOIN Employees
ON Orders.EmployeeID = Employees.EmployeeID
WHERE Employees.LastName = 'Davolio'} AS EmpOrders
RELATE EmployeeID TO EmployeeID)
If the parent and child tables do not have a one-to-many relationship; that
is, if EmployeeID is not a unique index or Primary Key of the Employees
table, the following alternative syntax using a sub-select is more general
and will work in all cases:
SHAPE {SELECT * FROM Employees WHERE LastName='Davolio'}
APPEND ({SELECT * FROM Orders WHERE EmployeeID IN
(SELECT EmployeeID FROM Employees WHERE LastName = 'Davolio')}
AS EmpOrders
RELATE EmployeeID TO EmployeeID)
This is somewhat more expensive in terms of server processing, but makes up
for it in terms of reduced network traffic.
189657 HOWTO: Use the ADO SHAPE Command
Additional query words: kbDSupport kbdse
Keywords: kbdatabase kbprb KB196968