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 3340894
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:39:37+00:00 2026-05-18T00:39:37+00:00

I am a total novice in DB2. I am trying to help someone else

  • 0

I am a total novice in DB2. I am trying to help someone else out who is an SQL Novice.

What I am trying to do would look like this in SQL Server:

declare @MaxValue int
select @MaxValue = Max(ID_COLUMN) from MainTable 

insert into MainTable (ID_COLUMN, OTHER_STUFF)
select TEMP_ID + @MaxValue, MORE_OTHER_STUFF
from   TempTable

How can I do this in DB2? (Bonus points if you can tell me a way to do this so that the inserted values into ID_COLUMN just keep counting from the current max.)

Note: I see a lot of examples saying you can declare a variable like this

DECLARE myvariable int;

but that is erroring out for us. So if you use that syntax maybe you can comment on why that does not work.

  • 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-05-18T00:39:37+00:00Added an answer on May 18, 2026 at 12:39 am

    What you have should work. look Here are you sure that you aren’t making a more perhiperal typo? perhaps in the start block of your proc.

    sounds like you want an identity column to me something like this.

    col3 INT NOT NULL GENERATED ALWAYS AS IDENTITY
                                         (START WITH 100, INCREMENT BY 5)) 
    

    if you are coming from SQL Server/Sybase, one nice thing with DB2 identity column is that they don’t ‘jump’ like they do on the afore mentioned platforms.

    If you need to know the last identity value generated, then you do something like this

     VALUES IDENTITY_VAL_LOCAL() INTO :MY_LOCAL_VAR_FOR_IDENTITY
    

    thus you could probably do you need to by doing the above two SQL statements and then returning the values

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Total newbie question but this is driving me mad! I'm trying this: myInt =
I am total begineer in ruby so its very novice question. I am trying
I am a total PHP novice and am trying to write what I think
This may be a lame question but I am a total novice with regular
I am a total novice at jQuery, but giving it a go. I cant
total nubi here and i'm trying to writ an application that trackes how far
Total newbie question, but I cant figure out what im doing wrong. I want
Am fairly new to using MySQL and a total novice at Perl but am
I'm fairly new to Linux (Ubuntu 10.04) and a total novice to assembler. I
I'm a novice Android programmer, and to help me understand how Intents really work,

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.