I've done this before, using a Script Component source.
You'll find articles online from others who have done this before. Here is an example.
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