|
-
Aug 8th, 2002, 09:58 AM
#1
Thread Starter
Fanatic Member
Access Query Needs Small Change
I have written a query within Access as follows:
UPDATE QueryInvoiceList SET NoOfDays = DateDiff("d",IIf(IsNull([DateReturned]),Date,[DateReturned]),[DateOnQuery])
It returns the number of days between datereturned and dateon query fields. It returns negative values i.e - 8 days. I need it to return postive values i.e. 8 days. I have written it the wrong way around and need to change it so that DateOnQuery minus DateReturned returns the number of days. If datereturned is null i want to use todays date.
I also have the following query which i need to add to the Update query above. It should calculate the average number of days.
SELECT AVG(NoOfDays)AS AvgDays FROM QueryInvoiceList;
Im not sure where to insert this, i keep getting a syntax error.
Any Access Query experts out there?
-
Aug 8th, 2002, 10:25 AM
#2
PowerPoster
UPDATE QueryInvoiceList SET NoOfDays = DateDiff("d",[DateOnQuery],IIf(IsNull([DateReturned]), Date,[DateReturned]))
-
Aug 8th, 2002, 10:49 AM
#3
Thread Starter
Fanatic Member
brillant thank you phind!! It works great.
Any one know how to add in the
SELECT AVG(NoOfDays)AS AvgDays FROM QueryInvoiceList;
Ive added it in like this..... but get a syntax error
Many Thanks
UPDATE QueryInvoiceList SET NoOfDays = DateDiff("d",[DateOnQuery],IIf(IsNull([DateReturned]),Date,[DateReturned])) AND SELECT AVG(NoOfDays)AS AvgDays FROM QueryInvoiceList;
-
Aug 9th, 2002, 05:36 AM
#4
Thread Starter
Fanatic Member
The query below returns the Number of days difference between two date fields.
I now need to derive an average from the number of days. Id like to display this average in a message box. Is this possible within my exisitng query.
UPDATE QueryInvoiceList SET NoOfDays = DateDiff("d",[DateOnQuery],IIf(IsNull([DateReturned]),Date,[DateReturned]));
Any ideas?
I received this access query average code below but cant get it to work...
SELECT AVG(NOOfDays)AS AvgDays FROM QueryTable
-
Aug 9th, 2002, 06:18 AM
#5
Addicted Member
Shouldn't there be a space between the closing brace and AS
SELECT AVG(NoOfDays)AS AvgDays FROM QueryInvoiceList;
SELECT AVG(NoOfDays) AS AvgDays FROM QueryInvoiceList;
I'm also guessing that an update and select query can't be executed in one shot.
J
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|