SELECT certain rows

Bobby9779

Registered User.
Local time
Today, 06:56
Joined
Aug 4, 2011
Messages
13
Has anyone got some SQL coding or can anyone point me in the right direction to solve my current conundrum?

I need a SELECT statment that selects the 1st record then every subsequent nth record.

Any ideas?
 
I suspect you'll need some VBA for that. A recordset has an AbsolutePosition property you can use, so code might be...
Code:
  const N as integer = 5
  dim rst as dao.recordset
  set rst = currentdb.openrecordset("yourQueryHere")
  do
[COLOR="Green"]    'process record data here[/COLOR]
    rst.absoluteposition = rst.absoluteposition + N
  loop
That code has some serious problems, but ...

And just out of curiousity, in what real-world situation does this process yield useful information?
 
I use this algorithm to get the previous ID of a table to build rolling reports. You could change the WHERE clause to "= ID + n" where n is how many subsequent rows you want to go. This assumes a unique Identity (autonumber) column.

This might be a start anyway.

SELECT ID AS AHID,
(SELECT MAX(ID) AS Expr1
FROM dbo.AthleteHydration AS ah1
WHERE (ID < ah.ID)) AS PreviousID
FROM dbo.AthleteHydration AS ah
 
My first thread was asking about appending unrelated queries/tables.

The SELECT statement I was using created a Cartesian Product, I thought I could get around it using this method. Looks like I can't!
 

Users who are viewing this thread

Back
Top Bottom