[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2009-07-14
4
Medium Priority
?
208 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 1500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

650 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