ok the complete sql is: (Ive put line spaces in for easy viewing, as the
select is prettymuch all one line.
still get the error stated previously..
SELECT [activity table].activity, [activity table].time, [activity
table].Dept, [activity table].Datein,
[activity table].Ward,
[activity table].cost,
[activity table].xtrstaff,
IIf([activity]="court apperance",30,0) AS extra,
[activity table].[reason for cancellation],
IIf([reason for cancellation]="refused by patient","0",IIf([reason for
cancellation]>"",[time],"0")) AS staffrefused,
IIf([reason for cancellation]="refused by patient",[time],"0") AS ptrefused,
[activity table].patient,
IIf([reason for
cancellation]>"",0,Sum(([xtrstaff]*([time]/60))+(IIf([activity]="court
appearance",30,0)))) AS xtrcost,
IIf([reason for cancellation]>"","0",Sum(([time]/60)*[cost])) AS coststaff,
IIf([reason for
cancellation]>"",0,Sum(([xtrstaff]*([time]/60))+(IIf([activity]="court
appearance",30,0))))+Sum(([time]/60)*[cost]) AS costtotal
FROM [activity table]
WHERE ((([activity table].Datein) Between [Forms]![frmptcost]![txtstart] And
[Forms]![frmptcost]![txtend]) AND (([activity
table].patient)=[Forms]![frmptcost]![cboname]));
IF there is another way around this, then i''m willing to look into it,
however i'm running out of time for this project and would just like
something that works for now, so working on this query would be the best at
this point in time...
many thanks
Steve
--
steve adlam
John W. Vinson said:
ok so made a little progress...
I how get an error.
i have a row with the code:
extra: IIf([activity]="court apperance","30","0")
This is not returning the *numbers* 30 and 0 - it's returning *text strings*.
Lose the quotes around 30 and 0.
this works fine, however when i try and add the next row, which references it:
xtrcost: IIf([reason for
cancellation]>"","0",Sum(([xtrstaff]*([time]/60))+[extra]))
You usually can't use a calculated field in a further calculation. Just
recapitulate the expression:
i get an error message:
You tried to execute a query tthat does not include the specified expression
'activity' as part of an aggregate function.
Please post the complete SQL of the query.
I'd REALLY rethink this. You're embedding a lot of business logic in these
complicated IIF statements, and you'll have a maintenance nightmare down the
road if the rules change.