Link to home
Start Free TrialLog in
Avatar of nirmal kumar
nirmal kumar

asked on

Iam getting this error "Operation must use an updateable query"

I have to take current date and a field from my table and need to calculate number of days in between  two dates using SQL in MS ACCESS

My Query is

UPDATE AllTickets SET Aging = (select DATEDIFF("d",NOW(),CreateTime) from AllTickets  )
WHERE [ReferenceNo] = 176698;

CreateTime is an Field in my table and it will have value like "8/12/2014 11:37:57 AM"
AllTicket is my Table name

Can anyone suggest me good solution?
SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nirmal kumar
nirmal kumar

ASKER

Hi Pawan ,
Thanks for your kind reply,
I tried the both the queries its saying "data type mismatch in criteria expression"
can you tell me data type of Aging and ReferenceNo ?
try this --
UPDATE AllTickets  
SET [Aging] =  DATEDIFF (  "d" , [CreateTime] , NOW()  ) 
WHERE [ReferenceNo] = 176698;

Open in new window


You should have #Date#..then it will work..
Avatar of Gustav Brock
If  [CreateTime] is not a date field, use:  DateDiff("d", CDate([CreateTime]), Now())

And/or if you have Nulls:  DateDiff("d", Nz([CreateTime], Now()), Now())

/gustav
Aging - Number
CreateTime - Date/Time
Then you probably have Null values.

/gustav
chk this

UPDATE AllTickets  
SET [Aging] =  DATEDIFF (  "d" , NZ([CreateTime],NOW()) , NOW()  ) 
WHERE [ReferenceNo] = 176698;

Open in new window

Yes ,I need to update those empty field with the calculated number of days
is above worked?
Hi Pawan,
UPDATE AllTickets  
SET [Aging] =  DATEDIFF (  "d" , NZ([CreateTime],NOW()) , NOW()  )
WHERE [ReferenceNo] = 176698;

The above query was also giving the same error
It is CreateTime that is the question - as I wrote:

And/or if you have Nulls:  DateDiff("d", Nz([CreateTime], Now()), Now())

/gustav
Then it could be No. that is a string. Try:

    WHERE [ReferenceNo] = '176698';

/gustav
check these..and tell me which one is working.

select DATEDIFF (  "d" , NZ([CreateTime],NOW()) , NOW()  )
WHERE [ReferenceNo] = 176698;

or

DATEDIFF (  "d" , NZ([CreateTime],NOW()) , NOW()  )
WHERE [ReferenceNo] = '176698';
Hi pawan,gustav
my ReferenceNo is "short text"
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes the above query is all you need...

Note that you should always put the string in single quotes for comparison.
UPDATE AllTickets  
SET [Aging] = DateDiff("d", [CreateTime], Now()) 
WHERE [ReferenceNo] = '176698';

Open in new window

Just FYI - Now() = Current Date + time of day.  For this purpose, you should be using Date()
UNLESS CreateTime also includes time of day and you want that to be considered in your calculation.
@Author - Do you need more help with this. :)
Solution provided.