34,838
社区成员




declare @sql varchar(max) =''
select @sql=@sql+'union all select a,b,'+''''+
name+''''+' from a where '+name+' is not null '
from sys.columns where object_id in(
select object_id from sys.objects where name='a')
and name not in('a','b')
set @sql=SUBSTRING(@sql,10,len(@sql))+' order by 1,2,3'
exec( @sql)