Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

SQL
INSERT INTO myTable
SELECT TOP(5) 5+Loc_code, Loc_Row
FROM myTable
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900