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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:30:02+00:00 2026-06-14T09:30:02+00:00

I have three scenarios that i’d like to handle, with some remapping i’m doing.

  • 0

I have three scenarios that i’d like to handle, with some remapping i’m doing.

Scenario #1
I have Table A

Column A, Column B
1, NULL
2, NULL
3, NULL
4,
NULL
5, NULL
6, NULL

How Can I Update Column B such that I begin with the next value of Column A

Column A, Column B
1, 7
2, 8
3, 9
4, 10
5, 11
6, 12

Scenario #2
I have Table A

Column A, Column B
1, NULL
1, NULL
2, NULL
2,
NULL
3, NULL
3, NULL
3, NULL

How Can I Update Column B such that I begin with the next value of Column A but insuring I only update the values as a group like so

Column A, Column B
1, 4
1, 4
2, 5
2, 5
3, 6
3, 6
3, 6

Scenario #3
I have Table A that contains gaps in Column A

Column A, Column B
1, NULL
1, NULL
4, NULL
4,
NULL
6, NULL
6, NULL
6, NULL

How Can I Update Column B such that I begin with the next value of Column A but insuring I only update the values as a group like so

Column A, Column B
1, 7
1, 7
4, 8
4, 8
6, 9
6, 9
6, 9

Can I possibly handle all three of these scenario’s in one statement? If so, how?
Any help is much appreciated!

  • 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-14T09:30:03+00:00Added an answer on June 14, 2026 at 9:30 am

    Try this:

    UPDATE t1
    SET t1.ColumnB = t2.ColumnB
    FROM @TableA t1
    INNER JOIN 
    (
       SELECT 
         ColumnA, 
         ColumnB = DENSE_RANK() OVER(ORDER BY ColumnA) 
                   + 
                   (SELECT MAX(columnA) FROM @tableA) 
       FROM @tableA
    ) t2 ON t1.ColumnA = t2.ColumnA;
    

    Here is the demos for the three scenarios:

    • SQL Server Column Mapping With the same sql statement- Scenario#1.

    • SQL Server Column Mapping With the same sql statement- Scenario#2.

    • SQL Server Column Mapping With the same sql statement- Scenario#3

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

Sidebar

Related Questions

I have 2 scenarios that I need some help with re validation in my
I have three different websites that uses some base classes, usercontrols. And my questions
Have three divs in a container that I want to float over a large
I have three separate table variables in my Function, 1 of them is not
I'm having some problems with encapsulation in C#. There are two specific scenarios that
I have three links in my Rails 3 app that load information in the
I have several hardware signals that get toggled based on properties relevant to scenarios
I'm creating an application whose main screen can consist of one of three Scenarios.
I have a scenario that I've been trying to figure out through any means
Consider the following three scenarios... Scenario A @import reset.css; /* ... */ p {margin:1em

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.