Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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.
Posted
Comments
Herman<T>.Instance 19-Feb-15 8:57am    
is there an ID field besides [S-no]?
Harpreet_125 19-Feb-15 9:27am    
This is not unique id column.. it can have duplicate values..
PIEBALDconsult 19-Feb-15 9:30am    
He says there's "one column" so I read that as "there are no other columns".
Harpreet_125 19-Feb-15 9:57am    
no, there are other columns also.
PIEBALDconsult 19-Feb-15 13:30pm    
That's not what you said.

1 solution

It really seems that the design is incorrect. The first thing you must understand is that the data is in no order. Another thing is that related data is stored in a single row (if it applies to single entity) or is joined by a reference when the data is spread to separate entities.

I think that the best advice at this point is to encourage you to get to know 3rd normal form (see http://en.wikipedia.org/wiki/Third_normal_form[^])

One easy way is to start from http://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm[^] and have a look at database normalization. There's a tutorial which wil guide you through first, second, and third normal forms. In my opinion this is what you probably should use in your situation.
 
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