当前位置: 代码迷 >> PB >> 怎么用存储过程,建动态列的数据窗口
  详细解决方案

怎么用存储过程,建动态列的数据窗口

热度:29   发布时间:2016-04-29 08:20:10.0
如何用存储过程,建动态列的数据窗口?
有一表:class
Student Course Score
------- ------- -----------
李四 数学 77
李四 物理 85
李四 英语 65
李四 语文 65
张三 数学 87
张三 物理 90
张三 英语 82
张三 语文 78

想转为行转列模式:
生成格式:
Student 数学 物理 英语 语文
------- ----------- ----------- ----------- -----------
李四 77 85 65 65
张三 87 90 82 78


建个存储过程(动态进行行列转换):
declare @s nvarchar(4000)
set @s=''
Select @[email protected]+','+quotename([Course])+'=max(case when [Course]='+quotename([Course],'''')+' then [Score] else 0 end)'
from Class group by[Course]
exec('select [Student][email protected]+' from Class group by [Student]')

那我如何用这个存储过程来建一个数据窗口?

------解决方案--------------------
试一下:

sqlca.syntaxfromsql('execute 存储过程名')
  相关解决方案