Quantcast
Channel: SCN : All Content - Data Services and Data Quality
Viewing all articles
Browse latest Browse all 4013

update rows

$
0
0

Hi guys

I need help to update null columns with values, see the sample data, to fill null values... I need to check all the null rows in between not null values order by ord irrespective of dates...and update the null values with the value filled in top not null row which means need to update the null values from top to bottom..

May be the description is little confusing that is why I provided the result sample which needs to be expected hopefully that will help you to provide me solution.

 

i tried using to find previous or next row... but that can update only 1 row at a time.. not as a lot...  could you please help me to provide the option so that all null values between not null rows can be updated with values....

 

CREATE TABLE tt (id INT,ord int,dt1 datetime, wd int)


INSERT INTO tt VALUES (102,'1','2013-05-27','544')
INSERT INTO tt VALUES (102,'2','2013-06-02',NULL)
INSERT INTO tt VALUES (102,'3','2013-06-03',NULL)
INSERT INTO tt VALUES (102,'4','2013-06-10',NULL)
INSERT INTO tt VALUES (102,'5','2013-07-08','690')
INSERT INTO tt VALUES (102,'6','2013-07-10',NULL)
INSERT INTO tt VALUES (102,'7','2013-07-10',NULL)
INSERT INTO tt VALUES (102,'8','2013-07-11','511')
INSERT INTO tt VALUES (102,'9','2013-07-11',NULL)

select * From tt

/******************************/

CREATE TABLE tt_result (id INT,ord int,dt1 datetime, wd int) 
INSERT INTO tt_result VALUES (102,'1','2013-05-27','544')
INSERT INTO tt_result VALUES (102,'2','2013-06-02','544')
INSERT INTO tt_result VALUES (102,'3','2013-06-03','544')
INSERT INTO tt_result VALUES (102,'4','2013-06-10','544')
INSERT INTO tt_result VALUES (102,'5','2013-07-08','690')
INSERT INTO tt_result VALUES (102,'6','2013-07-10','690')
INSERT INTO tt_result VALUES (102,'7','2013-07-10','690')
INSERT INTO tt_result VALUES (102,'8','2013-07-11','511')
INSERT INTO tt_result VALUES (102,'9','2013-07-11','511')

select * From tt_result


Viewing all articles
Browse latest Browse all 4013

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>