Convert row data to column in SQL Server
问题 Today I was asked by my colleague to transform data from a vertical staging table into a horizontal table. I mean transform rows to column. I used PIVOT and resolved it. But got into situation where I am getting trouble to move data if the data field repeats itself. Here is the test data that I am working on: CREATE TABLE STAGING ( ENTITYID INT, PROPERTYNAME VARCHAR(25), PROPERTYVALUE VARCHAR(25) ) INSERT INTO STAGING VALUES (1, 'NAME', 'DONNA') INSERT INTO STAGING VALUES (1, 'SPOUSE', 'HENRY