Solved

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

Posted on 2009-07-14
4
191 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:MaeMcG
  • 3
4 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24851887
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].
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24851911
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.
0
 

Author Comment

by:MaeMcG
ID: 24853908
I'm still confused?
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24854117
On which question?  On the one I posted, it seems that you are using my suggestion here to calculate the days to target as DATEDIFF("d", start_date, target_date).

For this question, since the calculation requires valid dates or date columns, you have to ensure that what you are passing to the function is correct.  My initial post was pointing out to you when running an UPDATE table you are making changes to underlying table data and not doing a SELECT; therefore, you should not see any results.  You should be seeing a prompt telling you the number of rows that were/will be impacted.

Additionally, you have this:
UPDATE [AUDIT ISSUES]
SET [AUDIT ISSUES].[Days To Target Date] = [b]DateDiff("d",[AUDIT ISSUES].[Date Opened],[AUDIT ISSUES].[Date Closed])[/b];

But in this query, you have this:
SELECT [Audit Issues].[ID], [Audit Issues].[Severity], [Audit Issues].[Auto Report Date], [Audit Issues].[Date Opened]
, [b]DateDiff("d",[Date Opened],[Auto Report Date]) AS [Days To Target Date][/b]
FROM [Audit Issues];

Note the differences of the text between [b] or in bold if the style is applied correctly.  If the one with [Date Closed] is not working, check that column is correct.  Also check if all your rows actual have dates for opened and closed dates.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now