Solved

Getting a field form my query into my database table

Posted on 2009-07-14
13
171 Views
Last Modified: 2012-05-07
I created a query that found the date difference between two fields of my original table. I would like this date difference field to go into my original table as a new field/column - how would I go about doing this? Is the query necessary - is there someway I can paste this datediff formula into my Access table?
0
Comment
Question by:MaeMcG
  • 7
  • 6
13 Comments
 
LVL 17

Expert Comment

by:pssandhu
ID: 24850400
In Access add another column to your table in Design View and then under properties for that column, under DEFAULT enter the formula to calculate the difference between the 2 columns in the same table. Eveytime yuo insert or update the fields the new column should update automatically.
P.
0
 

Author Comment

by:MaeMcG
ID: 24850546
Thank you so much for the quick reply - but unfortunately when I click properties under design view I only get "Default View" and do not just get "Default" (I am using Access 2003)... Also, is this the correct formula:
=DateDiff("d",[Date Opened],[Auto Report Date])

If those are the two fields I am looking to find the date difference between?

THANK YOU!
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24850681
Yes, it is infact called "Default Value". Sorry for not being clear on that. Please insert your formula there and hopefully that should do it.
And yes, the formual looks fine.
P.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:MaeMcG
ID: 24850723
Pssandhu - thank you, I will try that now. For my new column should I put the "Data Type" as a Date/Time, Number or Text? Thanks
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24850749
I think number should be fine here. Also, if this does not work, we will have to create a number column of type number and then write an UPDATE query to update the value in that table. So let me know how it goes.
P.
0
 

Author Comment

by:MaeMcG
ID: 24850763
This screenshot (see attachment) keeps appearing when I do what you say... thanks again.
screenshot.JPG
0
 
LVL 17

Accepted Solution

by:
pssandhu earned 500 total points
ID: 24851032
Hmm.. I had a feeling that it might error out. Alright so leave the new column that you added in but take out the formula in the Default Value box and save the changes to the table.
Then write an UPDATE query like this. This will be written in "SQL View". To get here create a query, right clicl on the header of the query window and select "SQL View".
UPDATE [AUDIT ISSUES]
SET [AUDIT ISSUES].[DAYS TO TARGET DATE] = DATEDIFF("d",[AUDIT ISSUES].[Date Opened],[AUDIT ISSUES].[Date Closed])
I am assuming your table name is ADUTI ISSUES. Please correct any column or table name errors.
P.
0
 

Author Comment

by:MaeMcG
ID: 24851254
I pasted exactly what you said on the SQL View... do I need to have SELECT [Audit Issues] in first and then paste what you told me?

This did not update my fields in my original Audit Issues table, instead it created a column/field named "DAYS TO TARGET DATE" in the Query Datasheet View?

Thanks P.
screen-shot-2.JPG
0
 

Author Comment

by:MaeMcG
ID: 24851296
What I mean to say is that it does not do any calculation, but whatever I do type into Days to Target Date will autopopulate my field.

Thanks!
0
 

Author Comment

by:MaeMcG
ID: 24851399

SELECT [Audit Issues].[Auto Report Date], [Audit Issues].[Date Opened], DateDiff("d",[Date Opened],[Auto Report Date]) AS [Days To Target Date]
FROM [Audit Issues];
UPDATE [AUDIT ISSUES] SET [AUDIT ISSUES].[Days To Target Date] = DateDiff("d",[AUDIT ISSUES].[Date Opened],[AUDIT ISSUES].[Date Closed]);
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24852208
First of all, when you run an update query you should get a pop up window saying "You are update these manu records" or somehting along the same line. You should not be seeing a datasheet view after you run the update query; all you will see are the pop windows as I described above.
And did you add the new column to the table without the default value? If you did then you should see an extra column with no values in that table when you open the table. The column should be of NUMBER datatype.
Also, are all the three column on the same table? What I mean is your "Date Opened", "Date Closed" and "Days to TargetDate" all on the same table? If not can you please explan what is the source table and how are the source and destination tables linked together.
No, you do not need a select statement before the update statement. The update statement should be al by itself.
Sorry for the delayed reply, I was stuck in a meeting.
P.
0
 

Author Comment

by:MaeMcG
ID: 24853952
How do I do the default value again - and how should I link the tables?

My original table is AUDIT ISSUES and I added a column/field "Days to Target Date"... I want the amount that my query (the one you gave me) to autofill or autopoulate into that column.

Thank you very much - and not a problem about being in the meeting. I'm a beginner here, so I appreciate your time and efforts in walking me through this.
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24859488
MaeMcg,
Can you please reply back to my questions I asked above before we can proceed any further? I am reiterating them below:
1. Are all the three column on the same table? What I mean is your "Date Opened", "Date Closed" and "Days to TargetDate" all on the same table?
2. If not, then can you please explan what is the source table and how are the source and destination tables linked together.
Also, can you please give me the exact names of the tables and column we are dealing with so that when I provide you with a solution, you will just have to copy paste?
Thanks
P.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL View Syntax case etc 5 34
SQL NULL vs Blank 26 36
Access Crosstab Query with Multiple Values 4 32
VB.net and sql server 4 35
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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