DECLARE @text VARCHAR(8000)
SET @text = 'select textNo,textName'
SELECT @text = @text + ', max(case TextDate when '''
+ CONVERT(VARCHAR(10), textDate, 23) + ''' then score else 0 end) ['
+ TextDate + ']'
FROM ( SELECT DISTINCT
[Date]
FROM [text]
) AS a
SET @text = @text + 'from text group by textNo,textName'
EXEC(@text)
SET @text = 'select textNo,textName'
SELECT @text = @text + ', max(case TextDate when '''
+ CONVERT(VARCHAR(10), textDate, 23) + ''' then score else 0 end) ['
+ TextDate + ']'
FROM ( SELECT DISTINCT
[Date]
FROM [text]
) AS a
SET @text = @text + 'from text group by textNo,textName'
EXEC(@text)
select distinct CONVERT(VARCHAR(50),textDate,110)as textDate from text没报错了