支点动态列,没有聚合
Question table
Answer table
Customer table
各栏:[CustomerID]
, [QuestionName_1]
, .., [QuestionName_n]
<- 动态
数据:CustomerID
, Answer_1
, .., Answer_n
DECLARE @columns VARCHAR(8000)SELECT @columns = COALESCE(@columns + ',[' + cast(QuestionName as varchar) + ']', '[' + cast(QuestionName as varchar)+ ']')FROM Answer A INNER JOIN Question Q ON A.QuestionID = Q.QuestionIDINNER JOIN Customer C ON A.CustomerID = C.CustomerIDGROUP B Y Q.QuestionNameSET @columns = '[CustomerID],' + @columnsDECLARE @query VARCHAR(8000)SET @query = 'Some PIVOT query without aggregation'EXECUTE(@query)
陪伴而非守候
相关分类