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!
Try this:
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