Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:18:19+00:00 2026-06-16T02:18:19+00:00

I have an existing table where a line sequence number is incremented by 100

  • 0

I have an existing table where a line sequence number is incremented by 100 in normal software operation. I need to perform a large insert and maintain this method of incrementation. I thought I would use ROW_NUMBER() but I do not know if it can increment in this way.

I’d appreciate help on that simple topic, however, if you want to get more specific please also note that the line sequence is unique for a Project and some records already started the sequence. For example

Project  Category  Sequence
Proj1    Cat4      100
Proj1    Cat2      200
Proj2    Cat7      100
Proj2    Cat1      200
Proj3    Cat1      100

So if these exist already and I am inserting new records, I have to account for the sequence already started for each project. So if I insert rows for Proj1, the Sequence value must be 300, 400, …

Here is my block of code so far:

WITH CTE (PROJECTNUM, COSTCATID, LINE) AS
(  SELECT PROJECTNUM, PACOSTCATID, ROW_NUMBER() OVER(PARTITION BY PROJECTNUM ORDER BY PACOSTCATID) 
      + (SELECT MAX(LNITMSEQ) FROM PROJECTTABLE WHERE PAPROJNUMBER = A.PROJECTNUM)
   FROM PROJECTSHORTLIST A, CATEGORYTABLE
   WHERE <stuff you don't care about>
)
INSERT INTO PROJECTTABLE
(PAPROJNUMBER, PACOSTCATID, LNITMSEQ)
SELECT PROJECTNUM, COSTCATID, LINE
FROM CTE;

You can see this will produce records incrementing by one and for Proj1 would be 301, 302.

Your brain power is greatly appreciated.

Update: I will add that if this incrementation by 100 can be more easily done in an update statement after the rows are first inserted that is perfectly acceptable. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:18:20+00:00Added an answer on June 16, 2026 at 2:18 am

    I’m answering my own question because 5 minutes after asking it, I thought of a solution. I moved the use of the “SELECT MAX()” portion down to the INSERT statement, leaving the row number intact for later use (I need it for additional columns). So in the SELECT portion of the INSERT I simply add ROW * 100 to my MAX sequence number.

    WITH CTE (PROJECTNUM, COSTCATID, ROW) AS
    (  SELECT PROJECTNUM, PACOSTCATID, ROW_NUMBER() OVER(PARTITION BY PROJECTNUM ORDER BY PACOSTCATID) 
       FROM PROJECTSHORTLIST A, CATEGORYTABLE
       WHERE <stuff you don't care about>
    )
    INSERT INTO PROJECTTABLE
    (PAPROJNUMBER, PACOSTCATID, LNITMSEQ)
    SELECT PROJECTNUM, COSTCATID, (ROW * 100) + (SELECT MAX(LNITMSEQ) FROM PROJECTTABLE WHERE PAPROJNUMBER = A.PROJECTNUM)
    FROM CTE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to insert the output of this code into an already existing table.
I have a DB table that already has an existing value that I don't
I have existing java code and need to create Design Document based on that.
I have problem with generating and inserting xml in existing document. <table:table table:template-name=default> <table:table-column
I have created a class which models my existing table in MySql database. Below
I'm trying to insert the data below into an existing table, and it gives
I have an existing recordset that retrieves all the information from a table in
I Have an ASP:Table that has a row with cells in I need to
I have quick question for you SQL gurus. I have existing tables without primary
I have an existing database with tables which each have 4 partitions (there are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.