I have the following table data:
name | serviceName | contractNo | materialNo
--------------------------------------------
item1 managed foo 123456 A6Ax33444
item1 managed bar 534454 A6A3222x7
And this is the result I need:
name | serviceName1 | contractNo1 | materialNo1 | serviceName2 | contractNo2 | materialNo2
item1 managed foo 123456 A6Ax33444 managed bar 534454 A6A3222x7
This example only contains two service-names but there may be zero to about 10 different services.
I tried several things using pivoting and dynamic SQL queries like this SQL Server: Examples of PIVOTing String data or Combine multiple rows into multiple columns dynamically in SQL Server but can't get it to work.
The real data is queried using multiple joins, 'name' comes from one table, 'serviceName', 'contractNo' and 'materialNo' are joined from another one and there are a lot more columns there, but the content is the same.
Thanks for help!