I
ianc
I would really appreciate some help. I've written the code below to produce
a running total in a query:
++++++++++++++++++++++++++++++++++++++
SELECT qry_stock_movement.stockistSN,
qry_stock_movement.grade_type_description,
qry_stock_movement.collection_date, qry_stock_movement.job_id,
qry_stock_movement.net_weight, (SELECT Sum(net_weight) FROM
qry_stock_movement As X WHERE X.collection_date <=
qry_stock_movement.collection_date AND X.stockistSN =
qry_stock_movement.stockistSN AND X.grade_type_description =
qry_stock_movement.grade_type_description ORDER BY
qry_stock_movement.stockistSN, qry_stock_movement.grade_type_description,
qry_stock_movement.collection_date) AS RunAmt
FROM qry_stock_movement
ORDER BY qry_stock_movement.stockistSN,
qry_stock_movement.grade_type_description, qry_stock_movement.collection_date;
+++++++++++++++++++++++++++++++++++++++
The nested SELECT does produce a running total but not at the level
required. There are a number of records with equal "collection_date"s which
gives me repeated totals ("RunAmt" values) for each record where the
collection date is the same, when what I want is individual totals for each
record within the same "collection_date" (within "stockistSN" and
"grade_type_description"). I can't see how to enhance this query further to
achieve this and have tried adding "AND X.job_id <=
qry_stock_movement.job_id" within the WHERE clause of the nested SELECT but
as the "job_id"s are not always sequential, this fails.
I hope this is enough detail, thanks in advance for any help.
Ian
a running total in a query:
++++++++++++++++++++++++++++++++++++++
SELECT qry_stock_movement.stockistSN,
qry_stock_movement.grade_type_description,
qry_stock_movement.collection_date, qry_stock_movement.job_id,
qry_stock_movement.net_weight, (SELECT Sum(net_weight) FROM
qry_stock_movement As X WHERE X.collection_date <=
qry_stock_movement.collection_date AND X.stockistSN =
qry_stock_movement.stockistSN AND X.grade_type_description =
qry_stock_movement.grade_type_description ORDER BY
qry_stock_movement.stockistSN, qry_stock_movement.grade_type_description,
qry_stock_movement.collection_date) AS RunAmt
FROM qry_stock_movement
ORDER BY qry_stock_movement.stockistSN,
qry_stock_movement.grade_type_description, qry_stock_movement.collection_date;
+++++++++++++++++++++++++++++++++++++++
The nested SELECT does produce a running total but not at the level
required. There are a number of records with equal "collection_date"s which
gives me repeated totals ("RunAmt" values) for each record where the
collection date is the same, when what I want is individual totals for each
record within the same "collection_date" (within "stockistSN" and
"grade_type_description"). I can't see how to enhance this query further to
achieve this and have tried adding "AND X.job_id <=
qry_stock_movement.job_id" within the WHERE clause of the nested SELECT but
as the "job_id"s are not always sequential, this fails.
I hope this is enough detail, thanks in advance for any help.
Ian