日期:2014-05-17 浏览次数:20514 次
ALTER PROC [dbo].[up_JXhuizong] (@JXtime varchar(50), @sql8 varchar(50)) as declare @str varchar(2000) set @str='' select @str=@str+',sum('+name+') as '+name from syscolumns where id=object_id('JXhuizong') and name not in('id','JXtime','姓名','UnitName','岗位履职','JXniandu') declare @col varchar(2000) set @col='' select @col=@col+'+'+name from syscolumns where id=object_id('JXhuizong') and name not in('id','JXtime','姓名','UnitName','岗位履职','JXniandu') print @col set @str='select row_number()over(order by getdate()) as id,UnitName as 部门,姓名,岗位履职' +@str+',(select '+RIGHT(@col,LEN(@col)-1) +' from JXhuizong b where a.姓名=b.姓名 and JXtime='''+@JXtime+''')as 加减总分 from JXhuizong a where JXtime='''+@JXtime+''' group by UnitName,姓名,岗位履职 '+@sql8+'' exec(@str)
------解决方案--------------------
所有动态列的和相加的结果AS 加减分
动态列1 动态列2 动态列3 。。。。。。
1 2 3
1 2 3
(sum(动态列1)+sum(动态列2)+sum(动态列3)) as 加减分
------解决方案--------------------
SELECT id,姓名,考核年度,岗位履职,对口考核, *宣传发表,*调研发表,*信息发表,*每日一题,*其他,SUM(TOTAL) FROM T ( SELECT id,姓名,考核年度,SUM(岗位履职) AS 岗位履职,SUM(对口考核) AS 对口考核, SUM(*宣传发表) AS '*宣传发表',SUM(*调研发表) AS '*调研发表', SUM(*信息发表) AS '*信息发表',SUM(*每日一题) AS '*每日一题',SUM(*其他) AS '*其他', (岗位履职+对口考核+*宣传发表+*调研发表+*信息发表+*每日一题+*其他) AS TOTAL FROM A GROUP BY ID,姓名,考核年度) T GROUP BY id,姓名,考核年度,岗位履职,对口考核, *宣传发表,*调研发表,*信息发表,*每日一题,*其他