J
James Cox
Problem: to generate ranking numbers for a subset of data in a table with a
SINGLE sql statement. The requirement for a single SQL statement is set by
contstraints of a third-party software package that will execute the SQL
against an Access database.
Background: Given a table All_Prod_Data with fields as shown below and with
many possible text values for the Department and UnitName fields
(AutoNumber) (Text) (Text) (Date/Time)
ReportID Department UnitName Date
The goal is to come up with a single sql select that will generate the
following
ReportID Department UnitName Date
SeqNumb
1235 Engines Block 12-Aug-04
12:23:45 1
589 Engines Block 12-Aug-04
16:02:19 2
2309 Engines Block 20-Aug-04
09:56:21 3
If I were starting with the above (except for the SeqNumb field) as a table
Some_Prod_Data, then this sql
SELECT PBDS1.ReportID, PBDS1.Department, PBDS1.UnitName, PBDS1.Date, (Select
Count(*) FROM Some_Prod_Data WHERE [Date] < [PBDS1].[Date]+1
AS SeqNumb
FROM Some_Prod_Data AS PBDS1 ORDER BY PBDS1.Date;
Would generate what we need.
My attempt to extend the above to include a WHERE statement to return only
specified Departments and UnitNames from table All_Prod_Data , i.e.
SELECT PBDS1.ReportID, PBDS1.Department, PBDS1.UnitName, PBDS1.Date, (Select
Count(*) FROM All_Prod_Data WHERE [Date] < [PBDS1].[Date]+1
AS SeqNumb
FROM All_Prod_Data AS PBDS1 WHERE ((PBDS1.Department = "Engines") AND
(PBDS1.UnitName = "Block")) ORDER BY PBDS1.Date;
Gave SeqNumb values that did not start with 1 and contained duplicate
values.
It's as if I need to do the SELECT for the particular Department and
UnitNames before the SELECT Count is implemented, but I don't know how to do
that. Any insights on how to modify the above to accomplish the goal?
Advance thanks for all help!
James Cox
SINGLE sql statement. The requirement for a single SQL statement is set by
contstraints of a third-party software package that will execute the SQL
against an Access database.
Background: Given a table All_Prod_Data with fields as shown below and with
many possible text values for the Department and UnitName fields
(AutoNumber) (Text) (Text) (Date/Time)
ReportID Department UnitName Date
The goal is to come up with a single sql select that will generate the
following
ReportID Department UnitName Date
SeqNumb
1235 Engines Block 12-Aug-04
12:23:45 1
589 Engines Block 12-Aug-04
16:02:19 2
2309 Engines Block 20-Aug-04
09:56:21 3
If I were starting with the above (except for the SeqNumb field) as a table
Some_Prod_Data, then this sql
SELECT PBDS1.ReportID, PBDS1.Department, PBDS1.UnitName, PBDS1.Date, (Select
Count(*) FROM Some_Prod_Data WHERE [Date] < [PBDS1].[Date]+1

FROM Some_Prod_Data AS PBDS1 ORDER BY PBDS1.Date;
Would generate what we need.
My attempt to extend the above to include a WHERE statement to return only
specified Departments and UnitNames from table All_Prod_Data , i.e.
SELECT PBDS1.ReportID, PBDS1.Department, PBDS1.UnitName, PBDS1.Date, (Select
Count(*) FROM All_Prod_Data WHERE [Date] < [PBDS1].[Date]+1

FROM All_Prod_Data AS PBDS1 WHERE ((PBDS1.Department = "Engines") AND
(PBDS1.UnitName = "Block")) ORDER BY PBDS1.Date;
Gave SeqNumb values that did not start with 1 and contained duplicate
values.
It's as if I need to do the SELECT for the particular Department and
UnitNames before the SELECT Count is implemented, but I don't know how to do
that. Any insights on how to modify the above to accomplish the goal?
Advance thanks for all help!
James Cox