473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Ascending number in query

I have an access query which gets data from a number of different
tables. Although the tables have primary key fields, the order in which
the records are returned means that none of these are in ascending
order in the query result set. I need to include in the query a field
that numbers the records in the order that they are returned. The
numbers must be unique and ascending but do not necessarily have to be
consecutive.

For Example:

Field ¦Date from¦No. from¦Name from¦ID from¦ID from¦ID from
I need¦table 1 ¦table 2 ¦table 3 ¦table 1¦table 2¦table 3
to add¦ ¦ ¦ ¦ ¦ ¦
¦ ¦ ¦ ¦ ¦ ¦
1 ¦1/1/1997 ¦ 24 ¦ Boris ¦ 28 ¦ 34 ¦ 68
2 ¦8/3/1998 ¦ 48 ¦ Tom ¦ 45 ¦ 12 ¦ 45
3 ¦8/3/1998 ¦ 1 ¦ Lucy ¦ 1 ¦ 51 ¦ 54
4 ¦4/9/1999 ¦ 15 ¦ Pam ¦ 29 ¦ 97 ¦ 83
5 ¦5/1/2000 ¦ 34 ¦ Marcel ¦ 14 ¦ 11 ¦ 87

Can this be done?

Nov 13 '05 #1
5 5554
On 14 Feb 2005 04:36:45 -0800, "?????" <al**********@hotmail.com>
wrote:

How do you know that "...that none of these are in ascending
order in the query result set..."? Because of the values in SomeField?
Then order by SomeField!

-Tom.

I have an access query which gets data from a number of different
tables. Although the tables have primary key fields, the order in which
the records are returned means that none of these are in ascending
order in the query result set. I need to include in the query a field
that numbers the records in the order that they are returned. The
numbers must be unique and ascending but do not necessarily have to be
consecutive.

For Example:

Field ¦Date from¦No. from¦Name from¦ID from¦ID from¦ID from
I need¦table 1 ¦table 2 ¦table 3 ¦table 1¦table 2¦table 3
to add¦ ¦ ¦ ¦ ¦ ¦
¦ ¦ ¦ ¦ ¦ ¦
1 ¦1/1/1997 ¦ 24 ¦ Boris ¦ 28 ¦ 34 ¦ 68
2 ¦8/3/1998 ¦ 48 ¦ Tom ¦ 45 ¦ 12 ¦ 45
3 ¦8/3/1998 ¦ 1 ¦ Lucy ¦ 1 ¦ 51 ¦ 54
4 ¦4/9/1999 ¦ 15 ¦ Pam ¦ 29 ¦ 97 ¦ 83
5 ¦5/1/2000 ¦ 34 ¦ Marcel ¦ 14 ¦ 11 ¦ 87

Can this be done?


Nov 13 '05 #2
The query set is ordered by date and this can be identical for a number
of records. I need a field that I can use to calculate a running total
down the result set which does not start from zero:

Total brought forward = 878

Date Value Running Total
01/01/05 35 913
02/01/05 12 925
02/01/05 48 973
03/01/05 5 978

The only way I know of to do this is to use DSum. For this I need to be
able to identify the current record and all records which come before
it. I cannot use the date as it would include records with the same
date even if they come after the current record in the result set.

Nov 13 '05 #3
????? wrote:
The query set is ordered by date and this can be identical for a number
of records. I need a field that I can use to calculate a running total
down the result set which does not start from zero:

Total brought forward = 878

Date Value Running Total
01/01/05 35 913
02/01/05 12 925
02/01/05 48 973
03/01/05 5 978

The only way I know of to do this is to use DSum. For this I need to be
able to identify the current record and all records which come before
it. I cannot use the date as it would include records with the same
date even if they come after the current record in the result set.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You need more data per row that uniquely identifies the row. E.g.:

PartID Date Value Running Total
25 01/01/05 35 913
30 02/01/05 12 925

The natural key for the above data appears to be PartID and [Date].
You'd use that in the running total subquery's WHERE clause:

WHERE PartID = MainQuery.PartID AND [Date] <= MainQuery.[Date]
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQhpFn4echKqOuFEgEQLJ8ACeOJZvJf68qtBZ9XjLzN+fD2 8XJPUAoNNe
TrBxaIKCo6NIid/l2DvvyW21
=YAYY
-----END PGP SIGNATURE-----
Nov 13 '05 #4
MGFoster <me@privacy.com> wrote in message news:<lA*****************@newsread3.news.pas.earth link.net>...
????? wrote:
The query set is ordered by date and this can be identical for a number
of records. I need a field that I can use to calculate a running total
down the result set which does not start from zero:

Total brought forward = 878

Date Value Running Total
01/01/05 35 913
02/01/05 12 925
02/01/05 48 973
03/01/05 5 978

The only way I know of to do this is to use DSum. For this I need to be
able to identify the current record and all records which come before
it. I cannot use the date as it would include records with the same
date even if they come after the current record in the result set.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You need more data per row that uniquely identifies the row. E.g.:

PartID Date Value Running Total
25 01/01/05 35 913
30 02/01/05 12 925

The natural key for the above data appears to be PartID and [Date].
You'd use that in the running total subquery's WHERE clause:

WHERE PartID = MainQuery.PartID AND [Date] <= MainQuery.[Date]
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQhpFn4echKqOuFEgEQLJ8ACeOJZvJf68qtBZ9XjLzN+fD2 8XJPUAoNNe
TrBxaIKCo6NIid/l2DvvyW21
=YAYY
-----END PGP SIGNATURE-----


The problem is that the records may not be unique. The part ID, date
and value could all be exactly the same. If this cannot be done in the
query is it possible to do it in the report? I cannot use the
RunningSum setting on the report field as I need to include the total
brought forward in the running total.
Nov 13 '05 #5
I have tried to add a running total field to my query but when I run
the query I get the error "Syntax error (missing operator) in query
expression" and every row in the running total column contains
"#Error". I have included the entire query below in case this helps.
Can anyone see where the problem is?

SELECT CL.CODE, CL.CLIENT, CL.COMPANY, [CBFWD query].BFWD, [YTD
query].[THIS YEAR], [YTD query].[WIP TOTAL], Year([DATE]) AS [YEAR],
TS.DATE, TS.[STAFF INITIALS], TS.WORK, [hours]*[rate] AS [value],
TS.HOURS, TS.RATE, TS.DESCRIPTION, TS.[Unique Ref], DSum("Value","TS","
[DATE] < " & [DATE] & " or ( [DATE] = " & [DATE] & " and [STAFF
INITIALS] < " & [STAFF INITIALS] & " ) or ( [DATE] = " & [DATE] & " and
[STAFF INITIALS] = " & [STAFF INITIALS] & " and [WORK] < " & [WORK] & "
) or ( [DATE] = " & [DATE] & " and [STAFF INITIALS] = " & [STAFF
INITIALS] & " and [WORK] = " & [WORK] & " and ([hours]*[rate]) < " &
[value] & " ) or ( [DATE] = " & [DATE] & " and [STAFF INITIALS] = " &
[STAFF INITIALS] & " and [WORK] = " & [WORK] & " and ([hours]*[rate]) =
" & [value] & " and [DESCRIPTION] < " & [DESCRIPTION] & " ) or ( [DATE]
= " & [DATE] & " and [STAFF INITIALS] = " & [STAFF INITIALS] & " and
[WORK] = " & [WORK] & " and ([hours]*[rate]) = " & [value] & " and
[DESCRIPTION] = " & [DESCRIPTION] & " and [Unique Ref] < " & [Unique
Ref] & " ) ") AS RunTot
FROM ((CL LEFT JOIN TS ON CL.CODE = TS.[CLIENT CODE]) INNER JOIN [YTD
query] ON CL.CODE = [YTD query].[CLIENT CODE]) INNER JOIN [CBFWD query]
ON CL.CODE = [CBFWD query].[CLIENT CODE]
GROUP BY CL.CODE, CL.CLIENT, CL.COMPANY, [CBFWD query].BFWD, [YTD
query].[THIS YEAR], [YTD query].[WIP TOTAL], Year([DATE]), TS.DATE,
TS.[STAFF INITIALS], TS.WORK, [hours]*[rate], TS.HOURS, TS.RATE,
TS.DESCRIPTION, TS.[Unique Ref]
HAVING (((CL.CODE)=[Please enter Client Code]) AND
((TS.DATE)>=DateSerial(3,3,31)) AND ((TS.WORK) Like [Enter optional
works code or * for all:]))
ORDER BY TS.DATE, TS.[STAFF INITIALS], TS.WORK, [hours]*[rate],
TS.DESCRIPTION, TS.[Unique Ref];

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wil smiths | last post by:
int i,j,val=4; int arr={4,7,3,9}; int temp=-1; int iptr=-1; for(i=0; i<=val-2;i++) { iptr=i; for(j=i+1;j<=val-1;j++)
1
by: Rich N | last post by:
When I open my form, I want the records already in it to be in Ascending Order based on one field. Though I keep putting them in Ascending order and then saving the form, each time I re-open the...
2
by: sunilkes | last post by:
I have a to only show date. I set the date to be in ascending order, but still 01/11/2006 shows first, and 31/10/2006 shows last..It is only ascending the date and not the complete date including...
11
by: dwelden | last post by:
I have successfully used the sort lambda construct described in http://mail.python.org/pipermail/python-list/2006-April/377443.html. However, how do I take it one step further such that some values...
6
by: askmatlab | last post by:
Hello all: I would like to insert a number into a linked list in ascending order. Is the following function correct? void insert(Node **node, int v) { Node *tmp = (Node...
3
by: Eric Lilja | last post by:
Hello, consider the following assignment and my code for it: /* Write a program that does the following: * Integer numbers shall be read from a textfile and stored in a std::vector. The name...
6
by: reon | last post by:
Here is my source code.... And any one pls help me how can we find the output integers sort by ascending and find there average... #include<iostream.h> #include<conio.h> void main() { int...
3
by: cess | last post by:
If the user input three numbers, say (1,3,2), how it will become 1,2,3 or in ascending order?? there is something wrong/lacking with my code, help plzzzz!! import java.io.*; public class sign {...
2
by: mpasschi | last post by:
MS Access 2002, in Windows XP. Hello all, could you please have a look at this problem description? I have a Query that shows in 'Design view' two fields in which the "Ascending" option is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.