万一您正在寻找动态枢纽
例子
Declare @SQL varchar(max) = 'Select *From ( Select * ,RN = row_number() over (partition by username order by UserId) from #YourTable ) A Pivot (max(UserID) For [UserName] in (' + stuff((Select distinct ',' + QuoteName([UserName]) From #YourTable Order By 1 For XML Path('')),1,1,'') + ') ) p'--Print @SQLExec(@SQL);
退货
RN Bob Rachel Simon1 445 512 7602 450 520 7713 NULL 570 NULL
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)