Answered by:

TSQL Counting Number of Occurrences of a Text Value

Question

I've been tasked with identifying number of consecutive F's in a students course history. My base query provides the sequential results below. However, I can't seem to get any code to generate the "Fgrades" column. This should
represent an occurrence value of the F grade in the students chronological course history. You'll notice the counter is reset when a grade breaks up the consecutive requirement. I'd appreciate some input on how one might accomplish this task.
I've spent quite a bit of time searching forums but can't identify information that applies to this nuance of Gaps and Islands. Thank you.

I'm working on this example and have a secondary requirement. With one student this code is perfect. When I add a second student, however, it breaks and I'm not quite sure why. I'm in BOL and think it has to do with partitioning but
haven't yet isolated the issue. In the graphic below, in row 12, I need to see the count restart like it does in row 5.