Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Query not working 1

Status
Not open for further replies.

psperry2

Programmer
Nov 7, 2007
141
US
I need to update a field in a temp table. When I run the Update Query, All I get is a view of the existing field data in the table I want to be updated. No update takes place.

UPDATE ztrptElapsed SET StartDate = (SELECT StepDateStart FROM tblPersons_Steps WHERE tblPersons_Steps.ISInvID = ZtrptElapsed.IsInvID AND tblPersons_Steps.StepID = 100);
 
Click the exclamation mark (run) icon rather than the view icon.

 
Ok now it tells me "Operation must use an updateable query
 
Try this
Code:
UPDATE ztrptElapsed Z INNER JOIN tblPersons_Steps P
       ON Z.IsInvID = P.ISInvID 

SET Z.StartDate = P.StepDateStart 

WHERE P.StepID = 100
 
Thank you Golom that worked! I tried to write the SQL in the same format I am used to in Transact SQL.



 
Access doesn't like coordinated sub-queries in UPDATE statements.

Transact-SQL (usually) doesn't have a problem with them as long as there's enough information to uniquely identify the records to be updated.
 
I need to write another update query on the same table, I have a field called Elapsed_Days and it is a calculated field based on the difference in days between the 2 dates, StartDate and Enddate.

Can the DateDiff Function be used in a Query?
 
this query works but if there is invalid dates it can produce a negative number. Is there a way to prevent the update if the DateDiff function produces a negative number?

UPDATE ztrptElapsed SET Elapsed_Days = DATEDIFF('d',StartDate,EndDate);
 
ok I answered my own question.

this works ok:

UPDATE ztrptElapsed SET Elapsed_Days =iif(DATEDIFF('d',StartDate,EndDate)>0,DATEDIFF('d',StartDate,EndDate),0);
 
another way:
UPDATE ztrptElapsed
SET Elapsed_Days = DATEDIFF('d',StartDate,EndDate)
WHERE EndDate>StartDate

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top