0

I have a table and the format is below:

Staff      Client   Problems Status
    1        101      a        1
    1        101      b        0
    1        101      e        1
    2        102      g        0

I want to create a report based on it and the format is as bellows and I do not know how many columns will be needed:

Staff        Client   Problem1 Status  Problem2  Status Problem3 Status.....
1            101         a       1           b       0      e      1
2            102         g       0

Can you assist with this? Thanks!

Ice
  • 429
  • 2
  • 6
  • 19
  • Search this site for "dynamic pivot" or "dynamic crosstab". There are dozens and dozens of this exact thing. – Sean Lange May 01 '17 at 20:59
  • 3
    Possible duplicate of [SQL Server dynamic PIVOT query?](http://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query) – Sean Lange May 01 '17 at 20:59
  • You can use dynamic SQL or pivot to have a query result give you the data you want, but you cannot create a table in SQL server with an unknown number of columns. It must be defined when creating the table. You could coalesce the values and split them when pulling them out. – Andrew O'Brien May 02 '17 at 00:11

0 Answers0