Hi @Ali Yılmaz
For static PIVOT query, please refer to Naomi and JingyangLi's answers which you need to type column names manually.
While in this issue, you could try dynamic PIVOT if there are too many columns you want to display.
Check this:
DECLARE @sql_str VARCHAR(MAX)
DECLARE @spread_elements VARCHAR(MAX)
DECLARE @Article VARCHAR(MAX)
SET @Article = '176E0AC3-1874-4801-BEB8-16E9B2F7D1FD'
SELECT @spread_elements = ISNULL(@spread_elements + ',','') + QUOTENAME(ASPD.English)
FROM ArticelSpec ASP inner join ArticelSpecDefinition ASPD ON ASP.ArticelSpecDefinition = ASPD.Oid
WHERE Articel=@Article
GROUP BY ASPD.English
--PRINT @spread_elements
SET @sql_str = '
SELECT * FROM
(
select top 100 ASP.Articel AS [Product Name], ASPD.English AS Ozellik, ASP.English
from ArticelSpec ASP inner join ArticelSpecDefinition ASPD on ASP.ArticelSpecDefinition = ASPD.Oid
where Articel='+@Article+'
)S
PIVOT (MAX(English) FOR Ozellik IN ( '+ @spread_elements +') ) AS P
ORDER BY [Product Name]
'
--PRINT (@sql_str)
EXEC (@sql_str)
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.