INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Enumerate Grouped Records in a Query

Enumerate Grouped Records in a Query

(OP)
Im trying to enumerate grouped records in a query. Please see table below.



The query is grouped and sorted by ID then depth. When I run the query I would like Depth_Enum to enumerate the depth values based on the grouping.
Any suggestion would be appreciated.
Thank You

RE: Enumerate Grouped Records in a Query

Post the SQL behind the query - specifically the ORDER BY clause...

Beir bua agus beannacht!

RE: Enumerate Grouped Records in a Query

(OP)
Thanks genomon:

The SQL is as follows:

CODE -->

SELECT tblPhysData.ColNum AS ID, tblPhysData.Depth
FROM tblStationInfo INNER JOIN tblPhysData ON tblStationInfo.ColNum = tblPhysData.ColNum
ORDER BY tblPhysData.ColNum, tblPhysData.Depth; 


So where I'm stuck is how to add a Depth_Enum field that enumerates the sorted depth value as shown in my example table (also known as group ranking?)

RE: Enumerate Grouped Records in a Query

Try something like:

CODE --> SQL

SELECT tblPhysData.ID, tblPhysData.Depth, "Depth_" & Count([tblPhysData_1]![ID]) AS Expr1
FROM tblPhysData INNER JOIN tblPhysData AS tblPhysData_1 ON tblPhysData.ID = tblPhysData_1.ID
WHERE (((tblPhysData_1.Depth)<=[tblPhysData]![Depth]))
GROUP BY tblPhysData.ID, tblPhysData.Depth; 

ID	Depth	Expr1
39	0.04	Depth_1
39	1.03	Depth_2
39	2.01	Depth_3
40	0.12	Depth_1
40	1.01	Depth_2
40	2.22	Depth_3
41	0.03	Depth_1
41	1.01	Depth_2
41	2.02	Depth_3 

Duane
Hook'D on Access
MS Access MVP

RE: Enumerate Grouped Records in a Query

(OP)
Thanks dhookom. When I insert the SQL code you provided into the query I get the following message:



Any suggestions?

Thank You

RE: Enumerate Grouped Records in a Query

Fishtek,
What is the exact SQL you tried in your query?

I had created a table with records as you suggested (without tblStationInfo) and it worked as expected for me.

Duane
Hook'D on Access
MS Access MVP

RE: Enumerate Grouped Records in a Query

(OP)
dhookom:

I believe I had a minor syntax error. I reworked the query and all is working fine now. Thanks so much for your help!

RE: Enumerate Grouped Records in a Query

Don't you think Duane deserves a Star for the help....?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close