A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @kasim mohamed ,
Thank you so much for posting here in Microsoft Q&A.
You could refer other experts' answers.
In case you have many columns in your table to pivot, you could refer below dynamic way:
declare @sql nvarchar(max)
select @sql=STUFF(( SELECT distinct ',['+_Name+']' FROM #table FOR XML PATH('') ), 1, 1, '')
set @sql=N' select p.* from #table
pivot ( max(_Code) for _Name in ('+@sql+')) p'
EXECUTE sp_executesql @sql
Output:
_ID ABC XYZ
11111 I10 A78.5
11112 I11 B78.5
11113 I12 C78.5
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
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.
]