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

  • Home
  • SEARCH
  • 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 8754559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:38:59+00:00 2026-06-13T13:38:59+00:00

I have a column that I need to update with codes in a temp

  • 0

I have a column that I need to update with codes in a temp table.There is +/- 5 codes in the temp table. Each row in the table must be updated with one of the values in the temp table.

Example
id  code
1   200
2   400
3   600
4   9000
5   800
6   200
7   400
8   600
9   9000
10  800
  • 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-13T13:39:00+00:00Added an answer on June 13, 2026 at 1:39 pm

    SQL Server Solution

    This query will sequentially take the values from the temp table and update the code in the example table in round robin fashion, repeating the values from temp when required.

    update e
    set code = t.code
    from example e
    join temp t on t.id = (e.id -1) % (select count(*) from temp) + 1
    

    If the ids are not sequential in either table, then you can row_number() them first, e.g.

    update e
    set code = t.code
    from (select *,rn=row_number() over (order by id) from example) e
    join (select *,rn=row_number() over (order by id) from temp) t
      on t.rn = (e.rn -1) % (select count(*) from temp) + 1
    

    The same technique (mod, row-number) can be used in other RDBMS, but the syntax will differ a little.

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

Sidebar

Related Questions

I have one table in my database that I want to update each year.
I have a table that I need to update where all columns are optionally
I have column with varchar values like 022008 that I need to convert into
I have a table of data that I need to dynamically add a column
So I have this SQL table that I need to update. Now we use
I have a table using jqGrid, I need that when editing a row some
I have an int id column that I need to do a one-time maintenance/fix
I have a column that I need to be able to guarantee never gets
I have an XML valued column that has multiple parent nodes. I need to
I have three columns in mysql table: tax_id, company_name, store_name. I need that tax_id

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.