clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3364508 fiddles created (36245 in the last week).

CREATE TABLE table1 ([Masked] varchar(19)) ; INSERT INTO table1 ([Masked]) VALUES ('5574-12XX-XXXX-1338'), ('6674-13XX-XXXX-0855'), ('7784-14XX-XXXX-5237'), (NULL), (NULL), (NULL), ('9984-11XX-XXXX-6196'), ('3384-11XX-XXXX-0615'), (NULL), (NULL) ;
10 rows affected
 hidden batch(es)


WITH #help1 as ( select * ,ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS Row# , case when [Masked] is null then 0 else 1 end as ChangeIndicator from [dbo].[table1] ) , #help2 as ( select *, Sum(ChangeIndicator) over (ORDER BY Row#) RowGroup from #help1 ) select case when [Masked] is not null then [Masked] else first_value([Masked]) over (partition by RowGroup ORDER BY Row#) end UnitsBalanceFillDown from #help2
UnitsBalanceFillDown
5574-12XX-XXXX-1338
6674-13XX-XXXX-0855
7784-14XX-XXXX-5237
7784-14XX-XXXX-5237
7784-14XX-XXXX-5237
7784-14XX-XXXX-5237
9984-11XX-XXXX-6196
3384-11XX-XXXX-0615
3384-11XX-XXXX-0615
3384-11XX-XXXX-0615
 hidden batch(es)