Greetings experts, I have a dynamic query that I integrated into a stored procedure. Here is the query: CREATE PROCEDURE dbo.uspGetPivotedData AS DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX); SET @cols = STUFF((SELECT distinct ',' + QUOTENAME(d.dateCreated) FROM DateDetails d FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'') set @query = 'SELECT employeeName,empTitle,email ' + @cols + ' from ( select employeeName , empTitle ,email , dateCreated,sourceincome from SourceDetails inner join Employees on SourceDetails.employeeID = Employees.EmployeeID inner join DateDetails on SourceDetails.employeeID = DateDetails.employeeID ) x pivot ( max(sourceincome) for dateCreated in (' + @cols + ') ) p ' EXECUTE sp_executesql @query
The query works great. The only thing that I would need your help in formatting is how to display dateCreated field as Year.
For instance, instead of April 2019, we would like to just display 2019.
Is this possible?
Thanks a lot in advance