I’ve climbed Rainier a couple of times and there were a few crevasses we had to cross. Some were just a mere jump, others were wider and had to be crossed with a ladder. Got me thinking about crevasses in data and how you might want to fill in those crevasses with the last known value until you cross to the other side and have data again.
Here’s a quick T-SQL tip to fill those crevasses:
Here’s your table:
select 1 as ID, ‘a’ as Col1 into #tmp1
union select 2, ‘b’
union select 3, NULL
union select 4, ‘d’
union select 5, NULL
union select 6, null
union select 7, ‘g’
Let’s say you want a new field where the NULLs will be replaced w/ the last known NULL value. So in this case, you want ID = 3 to have value of ‘b’ and IDs 5 and 6 to have value of ‘d’.
,MAX(t1.Col1) OVER (ORDER BY t1.ID ROWS UNBOUNDED PRECEDING) AS FillInTheBlank
FROM #tmp1 t1
Now go fill those crevasses in your data!