I have a table wqmp_gw_samp_technician_evw that looks like:
After my query I would like these results:
This is the query:
WITH pivot_data AS (select dbo.Initials(technician) technician, fcguid, ROW_NUMBER () OVER (PARTITION BY fcguid ORDER BY technician DESC) row_num from wqmp_gw_samp_technician_evw) select row_num, fcguid, technician_1, technician_2, technician_3 from pivot_data pivot (min (technician) for row_num in (1 technician_1, 2 technician_2, 3 technician_3) ) order by fcguid; <sorry, I tried to get out of this code block but can't get it to do that> The error message I receive is: Lookup Error - SQL Server Database Error: Incorrect syntax near '1'. dbo.Initials is a function that returns the initials of the technician. I admit that I am coming from Oracle, and this query works there, but now in MS SQL I'm stumped on how to show in a pivot the technician initials for each fcguid. Any insights are appreciated. Microsoft SQL Server 2016 (SP2-CU11-GDR) (KB4535706) - 13.0.5622.0 (X64) Dec 15 2019 08:03:11 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor) Sherrie