SQL Server - update column values which are null
Asked By Priyanka on 19-Feb-15 08:45 AM
I have one column in my sql database named as S-No.
Which has values like following :
S-No
____
1
____
2
____
Null
____
Null
____
3
____
Null
____
Null
____
Null
____
Null
____
Null
____
4
____
Null
.
.
Now, i want to write query in such a way that, which S-No column contains Null between 1 to 2, update there value to 1..... And which has Null between 2 To 3, update there value to 2... And so on... eg. 3 to 4 -- update as 3, 4 to 5 --- update as 4, 5 to 6...... I hope you will suggest me the query.. i am not able to write..
i hope you guyz will help.
Robbe Morris replied to Priyanka on 19-Feb-15 02:15 PM
standard sql doesn't have the concept of iterating row by row performing updates on different rows based on the condition of a given row. You are going to have to write code in your app that iterates through these rows and processes the logic you are after.
aneesa replied to Priyanka on 27-Feb-15 06:21 AM
UPDATE TABLENAME SET COLUMNAME=VALUE WHERE COLUMNAME IS NULL