Solved

How to create a consecutive numbers using a SQL sentence

Posted on 2008-10-29
2
682 Views
Last Modified: 2008-11-12
HI

I need to add records to an Access table using "Insert to" sentence, the point is that one of the fields needs to have a progresive value per each record, starting with a number previously defined.

Thanks

0
Comment
Question by:dimensionav
2 Comments
 
LVL 2

Accepted Solution

by:
gm1971 earned 125 total points
ID: 22838396
Hmmm, reaching way back here, but you could create an autonumber column, ramp it with garbage data to the starting number you need and then drop the rows before that.

Or create your own index column starting at the preferred number.
Then before each insert, have a query that pulls back the value of the last record and have it plus one, on the insert....

Don't use my code exactly cuz it sucks, but this might give you the idea....


SELECT MAX(NumIndex) AS MaxNumIndex
FROM myTable

Then in ASP set a variable called NewNumIndex=MaxNumIndex+1

Then on your insert

INSERT INTO myTable
VALUES NewNumIndex

Crappy pseudocode I know, but I'm not an ASP guy and I haven't used Access like that since about 99.
Hopefully this will get you pointed in the right direction though.


0
 

Author Comment

by:dimensionav
ID: 22855950
gm1971:

your code it´s ok (don´t worry), I´ll try it and I´ll let you know.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question