Criteria for Query Question (2 Viewers)

salbd

New member
Local time
Today, 02:15
Joined
Feb 4, 2024
Messages
2
I'm trying to create an update query that will change the status of residents who live in a building to "Yes" when they have lived there for at least 30 days. What would this criteria look like in datasheet view in Access? Fields would be Move In Date and Approved from a Rooms table.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:15
Joined
May 7, 2009
Messages
19,243
something like (if Status is a Yes/No field)

Update [ResidentTable] Set [Status] = -1 Where [DateFieldStartOfOccupancy] <= Date() - 30

if Status is a Short Text:

Update [ResidentTable] Set [Status] = 'Yes' Where [DateFieldStartOfOccupancy] <= Date() - 30
 

XPS35

Active member
Local time
Today, 08:15
Joined
Jul 19, 2022
Messages
159
It is a bad idea to store that in your table. You need to run the query every day.
Make a query with a calculated field and you can always show the right value at the current date
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:15
Joined
May 7, 2009
Messages
19,243
yes, like this:

Select *, IIF([DateFieldStartOfOccupancy] <= (Date() - 30), "Yes", "No") As NewStatus From [ResidentTable];

Or

Select *, Choose(Abs(([DateFieldStartOfOccupancy] <= Date() - 30)-1), "No", "Yes") As NewStatus From [ResidentTable];
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:15
Joined
Mar 14, 2017
Messages
8,777
Usually avoid storing calculated values in a table column. In larger scale enterprises, storing calculated values is not all that uncommon, but it's usually done to INCREASE efficiency and speed for dashboards or datamarts that need to be run and run fast during the day, so it may be useful to preaggregate the data (or even necessary, in many cases in my current job, where people really don't want to wait for queries to process billions of records every time they hit Update Dashboard!)



That's my best attempt at linking to some mentions about the balance of the issue
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:15
Joined
Feb 19, 2002
Messages
43,275
I'm trying to create an update query that will change the status of residents who live in a building to "Yes" when they have lived there for at least 30 days.
The problem with this request is that if you update the data today, then tomorrow some data will be wrong so unless you calculate the "yes" on the fly, you can never be sure your data is accurate.

EXACTLY what are you using this value for and why does it need to be stored? Why won't calculating it on a form or report on the fly work?
 

Users who are viewing this thread

Top Bottom