Solved

MS Access update statement with subquery in the set clause?

Posted on 2007-12-02
3
4,636 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
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 400 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

920 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

15 Experts available now in Live!

Get 1:1 Help Now