0

I have made a code as followed:

select 
PMGCONTACTPERSON.RECID                              AS  'Recid'
,PMGCONTACTPERSON.ROLEID                            AS  'Rol'
,DIRPARTYTABLE.NAME
from PMGCONTACTPERSON
left join DIRPARTYTABLE
ON  DIRPARTYTABLE.PARTYID = PMGCONTACTPERSON.PARTYID

result query

What I would like te get is columns named after the rolid and values filled with the names.

Any ideas?

Zhorov
  • 28,486
  • 6
  • 27
  • 52
  • 2
    What is the desired result? This isn't as simple as renaming some columns – Panagiotis Kanavos Aug 24 '20 at 07:42
  • So you want RoleID values be something like this" Opzichter Fred" – Atif Aug 24 '20 at 07:47
  • 2
    Does this answer your question? [Convert Rows to columns using 'Pivot' in SQL Server](https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) – Wouter Aug 24 '20 at 07:48

1 Answers1

0

I think you are looking to Pivot the table i.e. rows to columns. You can use PIVOT clause in SQL SERVER.

SELECT * FROM (
SELECT ROLE_NAME, NAME FROM TEST_NAME) T
PIVOT(MAX(NAME) FOR ROLE_NAME IN ([MANAGER], [ENGINEER])) AS PIVOT_TABLE;
Atif
  • 2,011
  • 9
  • 23