473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Update Query using if or iff function in MS Acess

Dear Sir,
Sub: help requred to build an Update Query using if or iif

I am having two tables with the following fields
I wish to create a single update query in MS Access

Table1: code, qty_x, qty_y, qty_z, qty_o ( code:ch, qty_x,qty_y, qty_z, qty_o : n)
Table2: code, qty, xyz ( code:ch, qty: n, xyz=ch)

Relationship created between the two tables on code field
Table2 contains records of repeated codes with qty, xyz fields as
“ x”, or “y”, or “z” , or “a”, or “b” (other than ‘x’, ‘y’, ‘z’)

Now I wish to update
Table1 qty_x field with the sum of qty of Table2 for xyz field=’x’ for the matching codes,
Table1 qty_y field with the sum of qty of Table2 for xyz field=’y’ for the matching codes,
Table1 qty_z field with the sum of qty of Table2 for xyz field=’z’ for the matching codes,
Table1 qty_o field with the sum of qty of Table2 for xyz fields=
other than ‘x’ ,’y’, ’z’ for the matching codes,

Please help me build up a single query in MS Access to update my database.

Thanking you,

Kannan, S
Aug 7 '06 #1
4 15439
PEB
1,418 Expert 1GB
Hi,
I've seen that in your Update query one of the tables is in agregate State, because you use the agregate function Sum!

So in this case you obtain an recordset that isn't updatable!

So to do an update in this case, you can place the agregate results of your table in a temporary table, using append query

Then you can join the temporary table and the table that you want to update. The relationship have to be in the follow format: one record from the table that you want to update must correspond only to one record of your corresponding table!

I hope that this help you!

Have a nice day!
Aug 31 '06 #2
PEB
1,418 Expert 1GB
FOR choosing which value to sum in the first query you can use the function switch(Criteria condition, result, criteria_condition1, result1 and so on...)
Aug 31 '06 #3
PEB
1,418 Expert 1GB
IIF also can help you!
Your append query:
INSERT INTO TEMP_TABLE (ID_f1,f2,f3,f4,f5)
SELECT ID, sum(IIF([xyz]="x",[qty],0)), sum(IIF([xyz]="y",[qty],0)), sum(IIF([xyz]="o",[qty],0))
FROM Table2;
Aug 31 '06 #4
PEB
1,418 Expert 1GB
INSERT INTO TEMP_TABLE (ID_f1,f2,f3,f4,f5)
SELECT DISTINCT ID, sum(IIF([xyz]="x",[qty],0)), sum(IIF([xyz]="y",[qty],0)), sum(IIF([xyz]="o",[qty],0))
FROM Table2;

OR

INSERT INTO TEMP_TABLE (ID_f1,f2,f3,f4,f5)
SELECT DISTINCT ID, sum(IIF([xyz]="x",[qty],0)), sum(IIF([xyz]="y",[qty],0)), sum(IIF([xyz]="o",[qty],0))
FROM Table2
GROUP BY ID;


:)
Aug 31 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
6
by: Greg Strong | last post by:
Hello All, In an 'Update' query can you use user-defined functions in the 'Update To' for the query? Either no or I'm missing something. See the additional info below. If I run a query...
11
by: DFS | last post by:
Architecture: Access 2003 client, Oracle 9i repository, no Access security in place, ODBC linked tables. 100 or so users, in 3 or 4 groups (Oracle roles actually): Admins, Updaters and ReadOnly....
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
19
by: kds14589 | last post by:
I'm new to acess and working on my first db. I haven't started using code yet so i still working with wizards. I am using Acess 2000 on an Windows XP. My problem is i have a time field that i need...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.