• so when I select line 2, there would be four columns, each with the boardings number in it, when I select line 4, there would be nine columns.

    Each row has a different number of columns? As long as you're only ever selecting one row at a time, this is a relatively simple piece of dynamic SQL and it doesn't have anything much to do with pivoting/cross-tabbing, which is converting multiple rows into multiple columns. You're generating multiple columns from a single row.

    What's your sample output for a given row? What are the columns called?