我有一组目前看起来像这样的数据:
出于报告目的,我必须透视InterviewNotes列。就我而言:
SELECT CandidateId, JobId, [1] AS Int1, [2] AS Int2, [3] AS Int3
FROM (SELECT CandidateId, JobId, InterviewNotes, InterviewNo FROM dbo.FactInterview) AS sourceTable
PIVOT (
MAX(InterviewNotes) FOR InterviewNo IN ([1],[2],[3])
) AS PivotTable
对于每一列,我想显示:InterviewName,InterviewDt,InterviewNotes连接。如:
Int1: InterviewerName - InterviewDt - InterviewNotes
Int2: InterviewerName - InterviewDt - InterviewNotes
答案 0 :(得分:1)
如果您想将InterviewerName
,InterviewDt
和InterviewNotes
连接在一起显示在最后一列中,请在PIVOT之前连接值:
SELECT CandidateId, JobId, [1] AS Int1, [2] AS Int2, [3] AS Int3
FROM
(
SELECT CandidateId, JobId, InterviewNo,
InterviewNotes = InterviewerName + ' - '+ convert(varchar(10), InterviewDt, 120) +' - '+ InterviewNotes
FROM dbo.FactInterview
) AS sourceTable
PIVOT
(
MAX(InterviewNotes) FOR InterviewNo IN ([1],[2],[3])
) AS PivotTable