?
Solved

MS Access update statement with subquery in the set clause?

Posted on 2007-12-02
3
Medium Priority
?
4,665 Views
Last Modified: 2012-05-05
Experts,
I am trying to run the following update this update statement works:

UPDATE MJM_ATTEND_PAY_INDIV SET MJM_ATTEND_PAY_INDIV.ATTEND_PER_MONTH = 4
WHERE (((MJM_ATTEND_PAY_INDIV.ROW_ID) In (SELECT [MJM_ATTEND_PAY_INDIV].[ROW_ID]
FROM MJM_SCHOOL, MJM_CLASS, MJM_STUDENT, MJM_ATTEND_PAY_INDIV
WHERE [MJM_SCHOOL].[ROW_ID]=[MJM_CLASS].[SCHOOL_ID] And
[MJM_CLASS].[ROW_ID]=[MJM_STUDENT].[CLASS_ID] And
[MJM_STUDENT].[ROW_ID]=[MJM_ATTEND_PAY_INDIV].[STUDENT_ID] And
[MJM_STUDENT].[ACTIVE_FLG] = -1 And  
[MJM_ATTEND_PAY_INDIV].[PAID_FLG]=0 And
[MJM_SCHOOL].[ROW_ID] IN (select row_id  from mjm_school as sc where sc.active_flg = -1 and sc.billing_flg = -1 and sc.payment_type = 'Individual') And
[MJM_ATTEND_PAY_INDIV].[BILLING_MONTH]=[Date])));

However instead of hardcoding the number 4 at the end of the set statement, I want to use a subselect:

UPDATE MJM_ATTEND_PAY_INDIV SET MJM_ATTEND_PAY_INDIV.ATTEND_PER_MONTH = (select config_value from mjm_lu_config where config_type = 'Week Override')
WHERE (((MJM_ATTEND_PAY_INDIV.ROW_ID) In (SELECT [MJM_ATTEND_PAY_INDIV].[ROW_ID]
FROM MJM_SCHOOL, MJM_CLASS, MJM_STUDENT, MJM_ATTEND_PAY_INDIV
WHERE [MJM_SCHOOL].[ROW_ID]=[MJM_CLASS].[SCHOOL_ID] And
[MJM_CLASS].[ROW_ID]=[MJM_STUDENT].[CLASS_ID] And
[MJM_STUDENT].[ROW_ID]=[MJM_ATTEND_PAY_INDIV].[STUDENT_ID] And
[MJM_STUDENT].[ACTIVE_FLG] = -1 And  
[MJM_ATTEND_PAY_INDIV].[PAID_FLG]=0 And
[MJM_SCHOOL].[ROW_ID] IN (select row_id  from mjm_school as sc where sc.active_flg = -1 and sc.billing_flg = -1 and sc.payment_type = 'Individual') And
[MJM_ATTEND_PAY_INDIV].[BILLING_MONTH]=[Date])));

I know the subselect only returns 1 row.  However, when I do this I get an error that says "query must be updateable".

I would think I would be able to do this, am I doing something wrong?

Thank you in advance for the help.

- Mike
0
Comment
Question by:uconnfb13
[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
  • 2
3 Comments
 
LVL 75
ID: 20391776
I'm not sure you can use a sub selelect stmt in the SET part of an update query.

mx
0
 
LVL 75
ID: 20391782
Possibly a DLookup instead ?

mx
0
 
LVL 16

Accepted Solution

by:
Rick_Rickards earned 1600 total points
ID: 20392213
PARAMETERS [Week Overide] Text ( 255 );
UPDATE MJM_ATTEND_PAY_INDIV SET MJM_ATTEND_PAY_INDIV.ATTEND_PER_MONTH = (select config_value from mjm_lu_config where config_type = [Week Override])
WHERE (((MJM_ATTEND_PAY_INDIV.ROW_ID) In (SELECT [MJM_ATTEND_PAY_INDIV].[ROW_ID]
FROM MJM_SCHOOL, MJM_CLASS, MJM_STUDENT, MJM_ATTEND_PAY_INDIV
WHERE [MJM_SCHOOL].[ROW_ID]=[MJM_CLASS].[SCHOOL_ID] And
[MJM_CLASS].[ROW_ID]=[MJM_STUDENT].[CLASS_ID] And
[MJM_STUDENT].[ROW_ID]=[MJM_ATTEND_PAY_INDIV].[STUDENT_ID] And
[MJM_STUDENT].[ACTIVE_FLG] = -1 And  
[MJM_ATTEND_PAY_INDIV].[PAID_FLG]=0 And
[MJM_SCHOOL].[ROW_ID] IN (select row_id  from mjm_school as sc where sc.active_flg = -1 and sc.billing_flg = -1 and sc.payment_type = 'Individual') And
[MJM_ATTEND_PAY_INDIV].[BILLING_MONTH]=[Date])));
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

770 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