Given a table with schema like this:
id1 id2 day number
How can I turn this:
a b day1 2
a b day5 4
a b day9 8
c d day2 1
c d day3 2
c d day5 4
c d day8 3
Into this?:
a b day1 2
a b day2 2
a b day3 2
a b day4 2
a b day5 4
a b day6 4
a b day7 4
a b day8 4
a b day9 8
c d day2 1
c d day3 2
c d day4 2
c d day5 4
c d day6 4
c d day7 4
c d day8 3
To clarify, for each group of id1 and id2, I need to fill in the missing rows
with dates ranging from the minimum date for that grouping to the maximum
date. Furthermore, the rows that get filled in must use the previous entry’s
number column for it’s number column.
I need this to run as fast as possible.
Bonus points if you can do it in LINQ to SQL (assuming the class exists for
the table).
EDIT: The day column is actually an int that represents the day, but for the sake of argument, it could be a date.
I’ve done the naive approach of iterating over each group and adding in the missing days, but it just seems terribly inefficient. I have to think that there’s something faster or that someone has encountered this situation before.
1 Answer