Solved

MS Access update statement with subquery in the set clause?

Posted on 2007-12-02
3
4,627 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
  • 2
3 Comments
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
I'm not sure you can use a sub selelect stmt in the SET part of an update query.

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Possibly a DLookup instead ?

mx
0
 
LVL 16

Accepted Solution

by:
Rick_Rickards earned 400 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
'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 …
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

8 Experts available now in Live!

Get 1:1 Help Now