简体   繁体   中英

Sql Server Pivoting

Trying to convert the row value to column (PIVOT) of the given table.

S.No          ID    Column2 Column3
1              1    1       Firstname
2              1    2       MiddleName
3              1    14      ContactNumber
4              2    1       Firstname
5              2    14      ContactNumber
6              3    14      ContactNumber
7              3    2       MiddleName

I want like below for ID 1

Column2 1           2           14
Column3 FirstName   MiddleName  LastName

please help me to solve it. Thanks

Looks like should be a simple CROSSTAB (PIVOT) query, like (syntax from Access database query builder):

TRANSFORM First(Table2.Col3) AS FirstOfCol3 
SELECT Table2.ID 
FROM Table2 
GROUP BY Table2.ID PIVOT Table2.Col2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM