VBA code/ selecting every 3rd record

serus

New member
Local time
Yesterday, 23:54
Joined
Apr 15, 2013
Messages
2
good evening i´ve problem with creating module in access.
I want to select every 3th row from "mytable" and create backup/copy of "mytable" and put into it this records.

I only have this query
SELECT *
FROM mytable
WHERE [TheColumn] Mod 3 = 0;

thank you for any advice
 
Last edited by a moderator:
Re: VBA code/ selecting every 3th record

You would have to choose what you want to order by. The table wouldn't technically have row numbers. The rows are relative to the order by.

So something like this might work (untested):
Code:
SELECT * FROM     
(SELECT ROW_NUMBER() OVER (ORDER BY Salary) AS Row, EmployeeId, EmployeeName, Salary
FROM Employees) AS EMP 
WHERE Row MOD 3 = 0

Source: www [dot] openwinforms [dot] com/row_number_to_sql_select [dot] html
 
Last edited:
Re: VBA code/ selecting every 3th record

Thanks, but
Code:
SELECT *
FROM Employees
WHERE [ID] Mod 3 = 0;
works when ID is autonumber for example.

What i need is select this every 3th record from "table(Employees)" and insert into "table (EmployeesCopy) using Access module.

thanks a lot
 
serus,

SELECT *
Into [EmployeesCopy]
FROM Employees
WHERE [ID] Mod 3 = 0;

Wayne
 

Users who are viewing this thread

Back
Top Bottom