Link to home
Create AccountLog in
Avatar of wlwebb
wlwebbFlag for United States of America

asked on

Access query Row Count with Criteria for a Yes/No field

Have a table named "Machine Number"

That table has fields:
MachineID (PK, Autonumber)
Active (Yes/No)
CompanyID (FK)


In my query, so that I can get a list with a sequential numbering of just "Active" machines, I have the following code:
SELECT (SELECT Count([MachineID]) FROM [Machine Number] A2 WHERE A2.[MachineID] < A1.[MachineID])+1 AS RowNum, *
FROM [Machine Number] AS A1
WHERE (((A1.Active)=-1))
ORDER BY A1.MachineID;

Open in new window


It is pulling all of the correct Items from the Table, however it is not creating the correct RowNum.

If I set the field for say MachineID 1 to be 0, then it is pulling MachineIDs 2, 3, 4 etc and starts the RowNum count at 2 instead of 1.

Any idea on where my code is missing starting its RowNum sequencing to include only the "Active" machinesid's?
SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of wlwebb

ASKER

Matthew
Thanks!  I was attempting Peter's suggestion when your answer came thru.  I have allocated a portion of the points to Peter for indicating where my theory was flawed.  Lion's share to you for the code also.
Glad to help :)