RomeoJuliet
Registered User.
- Local time
- Today, 23:20
- Joined
- Nov 20, 2008
- Messages
- 23
I have what I think should be a fairly table structure for orders: the tables are [Orders] and [Order Details], and I have queries [Orders Qry] and [Order Details Extended]. This is all based on Northwind.
I want to create a query which summarises orders, to be used in Excel; the user wants to use Excel for analysis.
Sales can be made in a variety of ways including via PayPal. I therefore want to add some expressions at the end of the query to calculate the Paypal charges and the nett total, but only if [PaymentType] = “PayPal”.
The query (based on [Orders Qry] and [Order Details Extended]) looks like this (with irrelevant bits excluded):
… however when I try to open it the response is “You tried to execute a query that does not include the specified expression ‘IIf([PaymentType]="PayPal",[SumOfExtendedPrice],Null)’ as part of an aggregate function.
What can I do about this?
Thanks
Mike.
I want to create a query which summarises orders, to be used in Excel; the user wants to use Excel for analysis.
Sales can be made in a variety of ways including via PayPal. I therefore want to add some expressions at the end of the query to calculate the Paypal charges and the nett total, but only if [PaymentType] = “PayPal”.
The query (based on [Orders Qry] and [Order Details Extended]) looks like this (with irrelevant bits excluded):
Code:
[FONT=Arial]SELECT DISTINCT [Orders Qry].OrderID, [/FONT]
[FONT=Arial]Sum([Order Details Extended].ExtendedPrice) AS SumOfExtendedPrice, [/FONT]
[FONT=Arial]First([Orders Qry].PaymentType) AS Payment_Type, [/FONT]
[FONT=Arial]IIf([PaymentType]="PayPal",[SumOfExtendedPrice],Null) AS PP_Gross, [/FONT]
[FONT=Arial]IIf([PaymentType]="PayPal",([PP_Gross]*0.034)+0.2,Null) AS PP_charges, [/FONT]
[FONT=Arial]IIf([PaymentType]="PayPal",[pp_gross]-[pp_charges],Null) AS PP_nett[/FONT]
[FONT=Arial]FROM [Order Details Extended] INNER JOIN [Orders Qry] ON [Order Details Extended].OrderID = [Orders Qry].OrderID[/FONT]
[FONT=Arial]GROUP BY [Orders Qry].OrderID[/FONT]
[FONT=Arial]ORDER BY [Orders Qry].OrderID;[/FONT]
What can I do about this?
Thanks
Mike.