Delhi XE3 Enterprise, SQL Server 2008
When I run the following the query it takes 4 seconds to run in the Delphi program. When I run it from SQL Server management studio it only takes .5 seconds to run.
SELECT
SUM(ISNULL(soi.ExtendedUnitPrice, 0)) AS TotalExtendedUnitPrice,
SUM(ISNULL(soi.ExtendedUnitCost, 0)) AS TotalExtendedUnitCost,
SUM(ISNULL(soi.OriginalTotal, 0)) AS TotalOriginalTotal,
SUM(ISNULL(soi.LineWeight, 0)) AS TotalLineWeight
FROM SalesOrderItems soi
WHERE (soi.SalesOrderID = :SalesOrderID)
To fix it I added the soi.SalesOrderID to the field list and added a GROUP BY SalesOrderID. Very quick now.