473,796 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I create an Autonumber field in a query?

39 New Member
I need to create an Autonumber field in a query I am currently running. The query right now calls fields such as names, addresses, phone numbers and is distinct on the client id. Each time I run the query I am calling for different sets of records off of the client id (ie: id's 50000-55000 or 32000-37000). Each time I run the query I need it to number the rows 1, 2, 3, 4, 5, ...5,000.
I hope this is understandable and someone can help.
Thanks
Feb 24 '11 #1
6 59186
mshmyob
904 Recognized Expert Contributor
If you wish to number your query row results just throw in a COUNT(*) or COUNT([ColumnName]) in your select query.

cheers,
Feb 24 '11 #2
Amy Badgett
39 New Member
Okay, for example... in a query like:

Expand|Select|Wrap|Line Numbers
  1. SELECT Clients.[Client ID], Clients.[First Name], Clients.[Last Name], Clients.Phone
  2. FROM Clients
  3. GROUP BY Clients.[First Name], Clients.[Last Name], 
  4. Clients.Phone , Clients.[Client ID];
  5.  
Where would that "Select Count([Client ID])" go?
Feb 25 '11 #3
mshmyob
904 Recognized Expert Contributor
It would just be another column in your column selection.

Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT([Client ID]), Clients.[Client ID], Clients.[First Name], Clients.[Last Name], Clients.Phone 
  2. FROM Clients 
  3. GROUP BY Clients.[First Name], Clients.[Last Name],  
  4. Clients.Phone , Clients.[Client ID]; 
  5.  
cheers,
Feb 25 '11 #4
Amy Badgett
39 New Member
Okay, so when I add the count, it just gives me a whole column of 1's, like it stops counting at the first record. Is there anyway to incorporate a loop? Or is that not right?
Feb 25 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Is this going into a report? You can just use a running sum in the report. If not, you'll need to use a subquery ranking.
Feb 25 '11 #6
mshmyob
904 Recognized Expert Contributor
Sorry try something like this if it is not in a report.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblB.[Client ID], tblB.[First Name], tblB.[Last Name], tblB.Phone, (SELECT COUNT(*) FROM Clients AS tblA WHERE tblA.[Client ID] <= tblB.[Client ID])
  2. FROM Clients
  3. GROUP BY tblB.[First Name], tblB.[Last Name],  
  4. tblB.Phone , tblB.[Client ID]; 
  5.  
cheers,
Feb 26 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5276
by: Mike Wiseley | last post by:
You can create a query in the SQL view that adds a new column to a table. For example, to add a new text field named X10, you use the following language: Alter Table MyTargetTable1 Add Column X10 text; Question: How can I make the new Column X10 be an AutoNumber field. The following does NOT work:
4
7749
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query, but I can't update record in query or in form. I believe the problem is due to the source query. In source query, there is a filter to show the incomplete record ("is null" in delivery date)], but I need to re-use the job no. if the job is...
3
7900
by: ben.werdmuller | last post by:
Hi, Is there an easy way in ASP/VBscript to grab an autonumber (primary key) field just after an SQL insert? This is probably easy, but I'm stuck .. Cheers.
1
2421
by: S. van Beek | last post by:
Dear reader, By append a new record to a table I always expect the next higher value in the range of the autonumber field. But sometimes if I have deleted same records from a table the behaviour of the autonumber field is changed.
5
2457
by: marko | last post by:
I would like my autonumber field to start at 100000. How can i do that?
6
6235
by: HS1 | last post by:
Hello I have a table in Access Database. This table has a AutoNumber field. I use a DataGrid to show that table When I insert a new record in for this table using a DataGrid, there is a message that asks me to enter the value for this AutoNumber field. Why I have to do that? Could you please help
9
60103
by: minjie | last post by:
I need to upgrade a MS Access database (Version 2002) with a script only, i.e., via SQL statement, not via Access GUI, and I'm having trouble defining an AutoNumber field. I got an exception error when running the follwoing (in a C++ program using ADO): ...... cmdStr = "CREATE TABLE mytab " "( AutoNumber, " " TEXT(50), " "CONSTRAINT PRIMARY KEY ()); ";
2
23471
by: ramzansadiq | last post by:
Hi guru's, I m unable to find how to Insert a primary key which is also an autonumber field into Table. My query is as below.It is inserting record if i m hardcoding the ID Field. It is VBA Access Insert into TableName(ID,LoginName,FirstName,LastName) Values(AutoNumber??,'Sam','Sam','Don') Insert into TableName(ID,LoginName,FirstName,LastName) Values(21,'Sam','Sam','Don') plz help me ASAP. Ram
2
2051
by: Richard Sherratt | last post by:
I've inherited a system that was designed by someone with no understanding of database design. From the logical design point of view, there is no logical design. The physical design is a nightmare. e.g. there are no relationships between tables and foreign keys appear to have been sprinkled at random like confetti. As an example, the Employer - Employee - Contract - Expense hierarchy has EmployerID in the Expense table. That's the...
7
3353
by: Qtip23 | last post by:
Hello Everyone, I have been searching for ways to prevent the autonumber field from increasing when a user decides he/she does not wish to enter a record. I searched Bytes and I think I saw something that alluded to setting up two distinct tables (let's call them Table B and Table C). Table B is the one with one field and the field name is the same as the Autonumber field of the host table in question (let's call it Table A). Then Table...
0
9531
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.