Link to home
Start Free TrialLog in
Avatar of MaeMcG
MaeMcG

asked on

DateDiff calculation and updating it into other field in original/parent table

I created a query that when a number is entered into it - the value will autopoulate and appear in the same field in another table.

SQL VIEW:
UPDATE [AUDIT ISSUES] SET [AUDIT ISSUES].[Days To Target Date] = DateDiff("d",[AUDIT ISSUES].[Date Opened],[AUDIT ISSUES].[Date Closed]);

However, I need my field named "Days To Target Date" to calculate the difference between two fields "Date Opened" and "Date Closed" but these are not appearing on my datasheet view of the query (I am attaching a screen shot)

I was able to create a separate query that was able to calculate the date difference
SQL VIEW:
SELECT [Audit Issues].[ID], [Audit Issues].[Severity], [Audit Issues].[Auto Report Date], [Audit Issues].[Date Opened], DateDiff("d",[Date Opened],[Auto Report Date]) AS [Days To Target Date]
FROM [Audit Issues];

So maybe it would be easier if I update that field "Days to Target Date" into my table - or combine the two somehow?

If somoene could help me with the formatting of what I should write in the SQL view to combine all of this -- that is, to have it find the date difference and autopopulate my original "Audit Issues" table that would be greatly appreciated.

THANK YOU.

screenshot-3.JPG
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

You original UPDATE statement should not have resulted in any results shown on screen, as you are not doing a select.  It should have prompted that you are about to change x number of records and you can proceed yes or no.  Verify the column names as in the update you use [Date Closed] but in the select where it "worked" you used [Auto Report Date].
And since you are using my solution for calculating the days until target, I would ask you please close this question - http:/Q_24566883.html.
Avatar of MaeMcG
MaeMcG

ASKER

I'm still confused?
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America 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