declare @sql varchar(max) declare @col varchar(max) set @col =(SELECT '['+SmsItemKey+']'+',' FROM #TEMP FOr xml path('')) set @col = substring(@col,1,len(@col)-1) set @sql = ' select ' + @Col + ' FROM SmsList' print @sql exec(@sql)
参考:http://www.cnblogs.com/doubleliang/archive/2011/07/06/2098775.html;
原文链接:https://www.f2er.com/xml/296678.html