Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Generating Sequential numbers in a column

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-09-07 : 11:07:41
I have created a table called Tracking in our database to load data from access.The data in access is imported from another source which has all the data needed to load except for Reqno column which has to be generated based on a number in another table in the database called CustomerHistory.

So after I load the data from accees to the tracking table i would have to generate Reqno column sequentially for the data loaded based on the value+5 in another table

Table Definition for CustomerHistory
CREATE TABLE [dbo].[Tracking](
[ReqNo] [int] NULL,
[Promonth] [datetime] NULL,
[Hrno] [int] NULL,
[customerno] [int] NULL,
[submissiondt] [datetime] NULL,
[confirmeddt] [datetime] NULL,
[Customerprice] [money] NULL,
[customercount] [int] NULL)


Table Definition for customerHistory

CREATE TABLE [dbo].[customerHistory](
[table_name] [char](25) NOT NULL,
[customerId] [int] NULL)

ashishseo
Starting Member

1 Post

Posted - 2011-09-08 : 07:48:12
How to create table?

Ashish kunar
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-09-08 : 07:53:19
Is CustomerID in customerHistory supposed to be used for this? If not, how do the tables relate?
Go to Top of Page

Lucian
Starting Member

1 Post

Posted - 2011-09-09 : 05:49:37
Add an Identity column (ID int identity(1,1) to the Tracking table.
Do load
Update Tracking set ReqNo = ID + @Value + 5

Drop Identity column if you want to

Not the most elegant solution, but it will do the job
Go to Top of Page
   

- Advertisement -