Solved How to Update a recordset without a loop? (1 Viewer)

KitaYama

Well-known member
Local time
Tomorrow, 02:25
Joined
Jan 6, 2022
Messages
2,239
If I have a DAO recordset, can I run an update on the recordset to update a field in all records , instead of using a loop and update one record at a time?
Something like an update query, but the object being a recordset instead of a table.

Thanks
 
Solution
Is it possible to write an update query, where the filter for the query is, let's say top 30 last records saved by a specific userFK in a table?
Yes
Code:
UPDATE your_table
SET column_to_update = 'New_value'
WHERE id IN (
    SELECT TOP 30 id
    FROM your_table
    WHERE userFK = 'specific_user_id'
    ORDER BY ID DESC
);
Is it possible to write an update query, where the filter for the query is, let's say top 30 last records saved by a specific userFK in a table?
Yes
Code:
UPDATE your_table
SET column_to_update = 'New_value'
WHERE id IN (
    SELECT TOP 30 id
    FROM your_table
    WHERE userFK = 'specific_user_id'
    ORDER BY ID DESC
);
 
Solution
Yes
Code:
UPDATE your_table
SET column_to_update = 'New_value'
WHERE id IN (
    SELECT TOP 30 id
    FROM your_table
    WHERE userFK = 'specific_user_id'
    ORDER BY ID DESC
);
I think it's the simplest way.
Thanks for your time and help.
I really appreciate it.
 

Users who are viewing this thread

Back
Top Bottom