• I'm just trying to figure out what OP needs to get as a result. My take, he needs

    - get a row set by splitting an initial row,

    - delete or add some null rows so that it's length was equal to parameter (31 in his post),

    - pivot or crosstab the result set to 31 columns as specified by parameter.

    So OP may need slightly modified Jeff Moden's DelimitedSplit8K() TVF and then crosstab it's output as described in his other articles. As a number of columns is parameter, crosstab should be generated dynamically.

    See links in Sean Lange's signature. 🙂