Showing Tag: "fill null rows with previous non null value" (Show all posts)

Fill null rows with previous non null value

Posted by Rajesh Setty on Tuesday, January 24, 2017, In : KnowledgeBase 
Requirement: In table which has row numbers and need to fill null value with previous non null value.

Solution: Using Cross Apply and Top 1 row

Tsql Syntax (Gen):

Select Coalesce(Tbl1.<Column1>,Tbl2.<Column1>) GTIN,Tbl1.* From Tbl Tbl1 --Coalesce would fetch first non Null Value
Cross Apply (Select top 1 <Column2> from Tbl Tbl2 -- Top 1 value would get only 1 record
             Where Tbl2.Row_Num <= Tbl1.Row_Num and <Column1> is not null --Row_N is row_number
             Order by Row_Num Desc) QE...
Continue reading ...
 
 
Make a Free Website with Yola.