Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / July 2006

Tip: Looking for answers? Try searching our database.

Update Query problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tiger0268 - 19 Jul 2006 16:04 GMT
I am not very experienced in SQL, so I need some help.  Alright, typically
when I create an update query, I do a select query and get my desired results
and then convert it over to an Update query; however, this time I have run
into a few problems.  I know it is simple, I just can't figure it out.  Below
is my select query:

SELECT MAIN.PostID, Count(MAIN.PostID) AS PostCount, MAIN.Title, First(MAIN.
PostDate) AS FirstOfPostDate, MAIN.PostNumber, MAIN.Post
FROM MAIN
GROUP BY MAIN.PostID, MAIN.Title, MAIN.PostNumber;

Basically, I have the following scenario:
ID     Title           Date        PostNumber           Post
1         string1     Date1             1                       Post1
1         string1     Date2             1                       Post2
2         string2     Date3             1                       Post3
2         string2     Date4             1                       Post4
3         string3     Date5             1                       Post5
3         string3     Date6             1                       Post6
3         string3     Date7             1                       Post7
...

I want it to look like this:
ID     Title           Date        PostNumber           Post         Expr:
Count    
1         string1     Date1             1                       Post1
2
2         string2     Date3             1                       Post3
2
3         string3     Date5             1                       Post5
3

And I want to assign the CountValue to the PostNumber.

ID     Title           Date        PostNumber           Post         Expr:
Count    
1         string1     Date1             2                       Post1
2
2         string2     Date3             2                       Post3
2
3         string3     Date5             3                       Post5
3
KARL DEWEY - 19 Jul 2006 18:12 GMT
Am I understanding you correct in that you want to update the same field that
you are counting?    You can not rollup records and update them at the same
time.  You could change your totals query to a make table query then use that
table to update the orignal table records.

> I am not very experienced in SQL, so I need some help.  Alright, typically
> when I create an update query, I do a select query and get my desired results
[quoted text clipped - 38 lines]
> 3         string3     Date5             3                       Post5
> 3
tiger0268 - 19 Jul 2006 18:30 GMT
Sorry for the confusion.  I am counting all records that are the same for
PostID.  Like in the below scenario, I should have a count of 2 for ID "1", 2
for ID "2", and 3 for ID "3".  I then want to update their respected
PostNumber field with their respected group count.  FYI...ID is not a primary
key or an autonumbering...it is more like an identifier I am using to group
LIKE items.

ID     Title           Date        PostNumber           Post
1         string1     Date1             1                       Post1
1         string1     Date2             1                       Post2
2         string2     Date3             1                       Post3
2         string2     Date4             1                       Post4
3         string3     Date5             1                       Post5
3         string3     Date6             1                       Post6
3         string3     Date7             1                       Post7

Should update to look like:

ID     Title           Date        PostNumber           Post
1         string1     Date1             2                       Post1
1         string1     Date2             2                       Post2
2         string2     Date3             2                       Post3
2         string2     Date4             2                       Post4
3         string3     Date5             3                       Post5
3         string3     Date6             3                       Post6
3         string3     Date7             3                       Post7

Is there a good way to do this or should I go with a make table query?

>Am I understanding you correct in that you want to update the same field that
>you are counting?    You can not rollup records and update them at the same
[quoted text clipped - 6 lines]
>> 3         string3     Date5             3                       Post5
>> 3
KARL DEWEY - 19 Jul 2006 19:02 GMT
I know of no other way than to use the make table.

But you do know that storing caluclated data is a bad idea as the
information gets outdated.

> Sorry for the confusion.  I am counting all records that are the same for
> PostID.  Like in the below scenario, I should have a count of 2 for ID "1", 2
[quoted text clipped - 35 lines]
> >> 3         string3     Date5             3                       Post5
> >> 3
tiger0268 - 19 Jul 2006 19:15 GMT
I was going to have the update query run on a every time a new record was
created on a form event so maybe I can just try and do it through VBA, but
thanks for helping.

>I know of no other way than to use the make table.
>
[quoted text clipped - 6 lines]
>> >> 3         string3     Date5             3                       Post5
>> >> 3
John Vinson - 19 Jul 2006 19:39 GMT
>I was going to have the update query run on a every time a new record was
>created on a form event so maybe I can just try and do it through VBA, but
>thanks for helping.

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox.

A Totals query will let you dynamically count the records. There is no
need or benefit to storing that count in your table.

                 John W. Vinson[MVP]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.