select @s=isnull(@s+' union all ','')+'select [Student],[Course]='+quotename(Name,'''')+',[Score]='+quotename(Name)+' from Class'
from syscolumns where ID=object_id('Class') and Name not in('Student')--排除不转换的列
order by Colid
exec('select * from ('+@s+')t order by [Student],[Course]')--增加一个排序此语句是动态的将列传行;我想问大家的是 在select syscolumns表时,为什么可以像游标一样 组合 where ID=object_id('Class') and Name not in('Student') 的所有行,它在这里的作用等价于是游标的作用,为什么?