Solved

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

Posted on 2009-07-14
4
186 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now