Update query with IIF statement (1 Viewer)

PMENDOZA

New member
Local time
Today, 17:45
Joined
Jul 29, 2018
Messages
7
I have an update query that needs to update data in JAN, FEB, MAR...fields in table A, based on the DATE field in linked table B.
I have the update set to:
JANBUD FEBBUD
IIF(Month([DATE_Field]=1,[BUDGET_AMOUNT],0) IIF(Month([DATE_Field]=2,[BUDGET_AMOUNT],0)
The problem I'm having is that it's only updating the last record, month 12, and nothing before that.
I have records with month numbers 1-12
I have attached the snapshot of the query.
Any help is much appreciated.
 

Attachments

  • QUERY.jpg
    QUERY.jpg
    89.5 KB · Views: 92

theDBguy

I’m here to help
Staff member
Local time
Today, 14:45
Joined
Oct 29, 2018
Messages
21,447
Hi. Try converting your UPDATE query into a SELECT query to see the records you will be updating. If it doesn’t look right, try adjusting your query to get the correct records.
 

Ranman256

Well-known member
Local time
Today, 17:45
Joined
Apr 9, 2015
Messages
4,339
I would make 12 queries. So they don't interfere w each other.
 

PMENDOZA

New member
Local time
Today, 17:45
Joined
Jul 29, 2018
Messages
7
Thanks. I was trying to avoid the 12 query route, which I know works.
When I run the select query , all the data for the records to be updated is there, but it's only updating the last one.
Thanks.:banghead:
 

isladogs

MVP / VIP
Local time
Today, 22:45
Joined
Jan 14, 2017
Messages
18,209
It's not possible to see the whole query so we can't tell why it fails.
However, your Top Account table isn't normalised.
You should not have 12 fields named JANBUD, FEBBUD etc.
Instead have two fields MonthBud and MonthNo or better still YearMonth e.g 1901
This should simplify your work significantly.
 

Users who are viewing this thread

Top Bottom