I am using Access 2000 front end with an SQL Server 7.0 backend database.
I have a table with Orders. Each order record (amongst other things) has a CustomerId, a TypeId, and each Order record has a TotalOrderValue.
I want to show a list of Customers, with a sum of TotalOrderValue, plus a break down by Type. There are only a handful of types and they are fixed, so I want it to look like this:
Total Type1 Type2 Type3 Type4
Customer_A 10245.67 2478.21 3952.00 1743.58 2071.88
In plain old Access 2000 I would do this as two seperate queries - one with the grandTotal, the other using IIF(Type="Type1", TotalOrderValue,0) type statements. I would then embed this one with the split amounts into the main one and use the normal sum totals.
The problem seems to be that with SQL Server, this leads to the 2nd (IIF) query pulling through every record, rather than only those it needs as indicated from query one (the one with the grand total, which incudes start date / end date parameters). This leads to the query taking a very long time to run.
I know about pass through queries, but I don't know how I would merge the SQL of the two queries to create one that works and is efficient.
Can anyone offer any help with the best approach to this type of query?
I have a table with Orders. Each order record (amongst other things) has a CustomerId, a TypeId, and each Order record has a TotalOrderValue.
I want to show a list of Customers, with a sum of TotalOrderValue, plus a break down by Type. There are only a handful of types and they are fixed, so I want it to look like this:
Total Type1 Type2 Type3 Type4
Customer_A 10245.67 2478.21 3952.00 1743.58 2071.88
In plain old Access 2000 I would do this as two seperate queries - one with the grandTotal, the other using IIF(Type="Type1", TotalOrderValue,0) type statements. I would then embed this one with the split amounts into the main one and use the normal sum totals.
The problem seems to be that with SQL Server, this leads to the 2nd (IIF) query pulling through every record, rather than only those it needs as indicated from query one (the one with the grand total, which incudes start date / end date parameters). This leads to the query taking a very long time to run.
I know about pass through queries, but I don't know how I would merge the SQL of the two queries to create one that works and is efficient.
Can anyone offer any help with the best approach to this type of query?