0

我有一组目前看起来像这样的数据:当前数据格式

出于报告目的,我必须旋转 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
4

1 回答 1

1

如果您希望InterviewerName,InterviewDtInterviewNotes连接在一起显示在最后一列中,则连接 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
于 2013-07-11T16:43:40.413 回答