I'm looking for an efficient way to convert rows to columns with dynamic column names in SQL Server. I heard that PIVOT
is not very fast, and I need to deal with a lot of records.
This is my example:
Id Name Type Address
----------------------------------
1 A Vendor Add1
2 B Vendor Add2
3 C Purchaser Add3
4 D Agent Add4
Required result:
Vendor Name Vendor Address Vendor 1 Name Vendor 1 Address Purchaser Name Purchaser Address Agent Name Agent Address
A Add1 B Add2 C Add3 D Add4
How can I build the result in which column names will create dynamic like if first value is vendor and if second time vendor will come then it will display look like vendor 1 + Name or Address?