Solved

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

Posted on 2009-07-14
4
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 60

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 60

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 60

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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