Hi,
I typically do the task I'm asking assistance with in Excel and it works great... the only problem is that it's VERY slow and takes a lot of work when over 1 million rows as you must split it up and yeah just painful! But what I'm trying to accomplish is pretty straight forward for Excel, however escapes me in T-SQL! I have an ordered number that is sorted asc. I have a flag that indicates a record is the "Parent". I want to update the family value for the "Parent" and all sequential records until the next "Parent" records is reached. So here is an example in Excel.
Using the following formula in cell C2 and pasting all the way to the last record, I can easily(for smaller sets anyway) create my desired results.
=IF(B2="Y",A2,C1)
Number Flag Family 1 Y 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 Y 9 10 9 11 Y 11 12 11 13 11 14 Y 14 15 14 16 14 17 14 18 14 19 14