SortRowField: Replaces the Month Numbers. Sets a field that will be used
for sorting the row data.

The AggregatedField
parameter poses a particular challenge, which makes it more difficult to
implement than the others. For that reason, we will focus on the other ones
today, and leave it for the next article.

Adding the remaining input paramters to the proc yields the
following code. Again, the new fields appear in Red for easy
identification:

Another
enhancement to the proc was to change the field aliases of the inner SQL to
utilize more generic naming. Hence, REGION_0X
becomes agg_fld_0X, Month_Num has been updated to sort_row_field, and
Month is now row_field. The outer query will always refer to these fields
by these names, regardless of what alias names are passed in.

One of the
perks of using dynamic parameters is that you are not limited to field names.
Functions such as MONTH(CREATION_DATE) and expressions such as Days
/ 4 are equally valid. We can now supply both the MONTH(CREATION_DATE)
and "MONTHNAME(CREATION_DATE)" functions to our proc: