用存储过程,构造一个表,其实这个就是交叉表,可以看看SQL Server的帮助,Search 交叉表
或在Sql Server版Search看看,很多的

解决方案 »

  1.   

    declare @sql varchar(8000)
    set @sql=''
    select @sql=@sql+',sum(case  when 功能名'''+功能名+''' then ''true'' else ''false'' end) as 功能'+功能id+' 
    from [function] 
    group by 功能名exec('select 模块'+@sql+' from [function] group by 模块名')
    --没调试
      

  2.   

    http://community.csdn.net/Expert/topic/3439/3439103.xml?temp=6.612796E-02
      

  3.   

    http://community.csdn.net/Expert/topic/3434/3434590.xml?temp=.7887689http://community.csdn.net/Expert/topic/3440/3440003.xml?temp=.1316645
      

  4.   

    declare @sql varchar(8000)
    set @sql=''
    select @sql=@sql+',max(case  when 功能名='''+功能名+''' then ''true'' else ''false'' end) as 功能'+cast(max(功能id) as char(2))+
    ',max(case  when 功能ID='+cast(max(功能id) as char(2))+' then 功能名  end) as 功能名 '
    from [function] 
    group by 功能名 order by max(功能id)exec('select 模块'+@sql+' from [function] group by 模块')
      

  5.   

    declare @sql varchar(8000)
    set @sql=''
    select @sql=@sql+',max(case  when 功能名='''+功能名+''' then ''true'' else ''false'' end) as 功能'+cast(max(功能id) as char(2))
    +','''+功能名+''''+'as 功能名'from [function] 
    group by 功能名 order by max(功能id)exec('select 模块'+@sql+' from [function] group by 模块')