I essentially want the table width to be dynamic.

A single group set of my table columns would look like this.

```
Rank   Method   Number   BasedOn
---------------------------------
1      E        1        Null
2      W        2        Null
3      P        3        math

```

A SQL `CASE` to choose what a column contains is fairly simple

```sql
CASE
   WHEN Method = 'P' THEN BasedOn
   WHEN Method = 'E' THEN 'E'
END AS BasedOn

```

What I would like, is that if I filter the 'Rank' such that 'P' isn't in any row of column 'Method', then the BasedOn column is not selected.

Thus the pseudo code would look something like this

```sql
SELECT 
    Rank,
    Method,
    Number,
    CASE 
       WHEN Method CONTAINS 'P' THEN END AS BasedOn
       ELSE  
    END
FROM
    Table1
WHERE
    Rank IN (1, 2)

```

returning

```
Rank   Method   Number
----------------------
1      E        1
2      W        2

```

but if

```sql
SELECT 
    Rank,
    Method,
    Number,
    CASE 
       WHEN Method CONTAINS 'P' THEN 
    END AS BasedOn
    ELSE END
FROM 
    Table1
WHERE
    Rank IN (2, 3)

```

Then it should return

```
Rank   Method   Number   BasedOn
---------------------------------
2      W        2        Null
3      P        3        Math

```

Is this possible? How should I be aggregating the 'Method' column in my check?