Standard forum etiquette is to leave your question unedited and to post the solution you found, for a couple of reasons:
- It may help others with similar requirements
- People here might suggest alternative solutions which perform better or are more elegant than the one you have found.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin