I am working with data that is grouped by item number with counts. Each record with a count > 2 needs to be blown out into individual records and compared at that level to a different set of data.
The data looks like this (It is stuck in this format. This is the only way the customer can send it.):
OwnerNumber ItemCode ItemNumber CountOfItems
1234 Item1 Item1-001 3
1234 Item1 Item1-002 1
1234 Item1 Item1-003 2
1234 Item2 Item2-001 1
And I need the data formatted like this (dynamically without hardcoding for value of CountOfItems):
OwnerNumber ItemCode ItemNumber
1234 Item1 Item1-001
1234 Item1 Item1-001
1234 Item1 Item1-001
1234 Item1 Item1-002
1234 Item1 Item1-003
1234 Item1 Item1-003
1234 Item2 Item2-001
For some reason I just can’t wrap my head around a clean way to do this (or any way).
You can manage with a Common Table Expression
Edit:
Added
MAXRECURSIONto handle situations where CountOfItems exceeds default max recursions as pointed out by Dev_etter