Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update SQL using another table

Status
Not open for further replies.

KavJack

Programmer
Apr 1, 2001
46
I need help on Updating a Table. Can anybody fix my UPDATE SQL ?
I have a Table SEASON&Count
which has 3 all numeric fields:SEASON,Number_Of_Teams,Number_Of_Games.
I want to update the Number_Of_Games field which is calculated as the number of games played in a season.
SELECT CUPALL2.YR AS SEASON, Count(CUPALL2.HT) AS CHT
FROM CUPALL2
GROUP BY CUPALL2.YR;
This SQL counts the number of games that are played for each season (CUPALL2.YR) and is stored as a query "SelectYRCount" generating two fields SEASON,CHT.
The UPDATE SQL that I wrote is
UPDATE [SEASON&Count] SET [SEASON&Count].Number_Of_Games = (SELECT CHT FROM SelectYRCount
WHERE SelectYRCount!SEASON = [SEASON&Count]!SEASON);
When I try to run this I get the message "Operation must use an Updatable Query". I am using Access 97 / Windows 98. A bit ancient, I know, but economy prevails right now.
What am I doing wrong ?

 
what record are you trying to update? some possiblities.

UPDATE [SEASON&Count] SET [SEASON&Count].Number_Of_Games = (SELECT CHT FROM SelectYRCount
WHERE SelectYRCount!SEASON = [SEASON&Count]!SEASON)
Where [SEASON&Count]!SEASON) = the record to be updated;

UPDATE [SEASON&Count] SET [SEASON&Count].Number_Of_Games = (SELECT CHT FROM SelectYRCount
WHERE SelectYRCount!SEASON = [SEASON&Count]!SEASON)
Where [SEASON&Count]!SEASON) = SelectYRCount!SEASON ;
 
I want to update every record with the appropriate count of the number of games for every season.
My table SEASON&Count looks like this :
Season Number_of_teams Number_of_Games
1872 16 0
1873 17 0
1874 29 0
.. .. ..
2000 580 0

The goal here is to get all the zeroes in the Number_of_Games column replaced by the correct count as I tried to indicate by quoting my SQL example. So it is not just a one line update. The SQL yuo gave in your response did not work. When trying to run it, I got the Enter Parameter Dialog box with "SelectYRCount!SEASON" as a supposed parameter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top