说明
一、建立表
主要有三列
列:FeeDeptID(科室编号),ItemiD(项目编号),金额
FeeDeptID,ItemiD关联其他表
二、创建存储过程
Create PROCEDURE 存储过程1
@fromDate date,
@ToDate date,
@people varchar(8)
AS
Declare @s varchar(8000)
Set @s = ''
Select @s = @s +','+B.ItemName+'= sum(case itemid when '''+B.itemName+''' then 金额 else 0 end)'
from Fee_DataUpload a,fee_items b where a.itemid=b.itemid and A.上传人=@people
and 日期 between @fromDate and @ToDate
group by B.itemName order by B.itemName
Exec ('select A.FeeDeptID 科室编号,b.FeeDeptName 科室名称'+
@s+
',sum(金额) As 合计 from Fee_DataUpload a ,Fee_depts B where a.feedeptid=b.feedeptid '+
' group by A.FeeDeptID,b.FeeDeptName order by A.feedeptid,b.FeeDeptName ')
三、在应用程序中调用存储过程
语法:Exec 存储过程1 @fromDate='2023-01-01', @ToDate='2023-01-01', @people='tt'
标签:itemid,01,示例,people,Server,Fee,fromDate,SQL,FeeDeptID From: https://www.cnblogs.com/Biyuanguang/p/17233054.html