sql(124分)

  • 主题发起人 主题发起人 zlibo
  • 开始时间 开始时间
写case一定能完成!
 
--SQL SERVER 2000 的存储过程 你自己修改一下
Create procedure TestProc
as
begin
declare @SqlText varchar(8000), @TmpSql varchar(7000)
declare @TmpTable table(ID int identity(1,1), [month] int)
insert into @TmpTable([month]) select DISTINCT [month] from TbSalery order by [month]
declare @MID int, @MCount int, @MValue varchar(10)
select @MCount = count(1), @MID = 1 from @TmpTable
set @TmpSql = ''
while @MID <= @MCount
begin
select @MValue = [month] from @TmpTable where ID = @MID
if @MID <> @MCount
set @TmpSql = @TmpSql + 'sum(case when [month] = ' + @MValue + ' then Salery else 0 end) ' + '[' + @MValue + '] ' + ' ,' + char(13)
else
set @TmpSql = @TmpSql + 'sum(case when [month] = ' + @MValue + ' then Salery else 0 end) ' + '[' + @MValue + '] ' + char(13)

set @MID = @MID + 1
end
set @SqlText = 'select name, ' + char(13) + @TmpSql + char(13) + 'from TbSalery group by name'
--print @SqlText
exec(@SqlText)
end
 
to dhszxh:
用case怎么写?
 
to hityou:
我该怎么测试这个存储过程运行的结果呀,不要不耐烦呀,好人做到底[:D]
 
exec p_sta .把这个放在query里面执行就可以.
 
不用存储过程能不能实现,如果用fastreport报表能实现也行
 
使用:
frUserDataset控制数据就可以了。
 
楼上能不能说得详细一点,谢谢
 
根据类别产生对应的交叉表语句,
或者按照,工序,然后用
JOIN 条件就是工序。
存储过程写法也是如此,呵呵没有什么简单方法
 
多人接受答案了。
 
后退
顶部