Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
I have a table with column c1,c2 c3.
Here it is.
c1  c2   c3
1   2   NULL
2   3   NULL
3   4   NULL
4   5   NULL

My requirement is that using a single update statement i need to fill the column c3 with c1 data.
Except the first row, the remaining columns need to be updated with data from column c1.

The desired output is:

c1  c2  c3
1   2   NULL
2   3   1
3   4   2
4   5   3

Thanks in advance.
gvprabu 7-May-13 4:23am    
C1, C2, C3 values are in same Ascending order like 1,2,3,4...
If its different u need to go for SUB Query and find the values for Each Data in C1 Columns then u ll do for Multiple Update (Update with Select Statement)

if it's series then simply,
select c1,c2,case when (c1-1)=0 then NULL else (c1-1) end as C3
from tblnm

Happy Coding!
Share this answer
M S Chaitanya 6-May-13 1:57am    
Thank u.. that was so simple..
but i asked for an update..
Aarti Meswania 6-May-13 1:58am    
Glad to help you! :)
StianSandberg 6-May-13 2:23am    
Aarti Meswania 6-May-13 2:27am    
Thank you! :)
set c3 = c1
where c1 <> 1

Scratch that... I answered your actual question rather than what you showed in your sample data.
Share this answer

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