Click here to Skip to main content
14,459,531 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hye all..

I want to update multiple rows with different values which I retrieve from top n rows in the same table. Here the example to give a clearer picture.

Loc_code | Loc_Row
-------- --------
1 | R1
2 | R2
3 | R3
4 | R4
5 | R5

And i want to copy Top 5 Loc_Row values into Loc_Row with Loc_Code between 6 and 10

Loc_code | Loc_Row
-------- --------
6
7
8
9
10

Is it possible? Thanks.
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

INSERT INTO myTable
SELECT TOP(5) 5+Loc_code, Loc_Row
FROM myTable
   
Comments
snamyna 26-Sep-12 2:25am
   
Thanks Kuthuparakkal. That solves 1 of the problem which inserting multiple rows. But my question is how to update the rows from row number 6 to 10 for column Loc_Row to be the same values as loc_code 1 to 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100