use aqgl
alter table wgsr add je float
alter table zbkh add je float
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- SELECT * FROM WGSR update wgsr set je=10
ALTER procedure P_AJCWGKHTJ -- EXEC P_AJCWGKHTJ '2001-01-01','2009-01-01'
@daks varchar(30),
@dajs varchar(30)
as
DECLARE @LX VARCHAR(30)
declare @str varchar(4000)
set @str='SELECT xh 人员编号, xm 姓名, djrKQH 卡号, zw 职务, lb 人员类别 '
DECLARE CR CURSOR FOR
SELECT LX from AJCWGLX ORDER BY ID
OPEN CR
FETCH NEXT FROM CR INTO @LX
while (@@fetch_status=0)
BEGIN
SET @STR=@STR + ',(SELECT COUNT(WGBH) FROM WGSR
WHERE WGLX=''' + @LX +''' AND WGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') AS '''+@LX +''''
--------------------------------------------------------------
FETCH NEXT FROM CR INTO @LX
END
CLOSE CR
DEALLOCATE CR
SET @STR=@STR+', (SELECT SUM(WGKF) FROM WGSR
WHERE WGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') 扣分合计
, (SELECT SUM(je) FROM WGSR
WHERE WGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') 罚款合计
FROM ( SELECT xh,kqh as djrkqh,bm,xm,zw,lb,zy from daxx where bm='''+'安监处'+''') as daxx
order by xh '
--print @str --select * from dksr
exec (@str)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- SELECT * FROM WGSR
ALTER procedure P_AJCWGKHzb -- EXEC P_AJCWGKHTJ '2001-01-01','2009-01-01'
@daks varchar(30),
@dajs varchar(30)
as
DECLARE @LX VARCHAR(30)
declare @str varchar(4000)
set @str='SELECT xh 人员编号, xm 姓名, djrKQH 卡号, zw 职务, lb 人员类别 '
DECLARE CR CURSOR FOR
SELECT LX from AJCWGLX ORDER BY ID
OPEN CR
FETCH NEXT FROM CR INTO @LX
while (@@fetch_status=0)
BEGIN
SET @STR=@STR + ',(SELECT COUNT(WGBH) FROM WGSR
WHERE WGLX=''' + @LX +''' AND zWGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') AS '''+@LX +''''
--------------------------------------------------------------
FETCH NEXT FROM CR INTO @LX
END
CLOSE CR
DEALLOCATE CR
SET @STR=@STR+', (SELECT SUM(WGKF) FROM WGSR
WHERE zWGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') 扣分合计
, (SELECT SUM(je) FROM WGSR
WHERE zWGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') 罚款合计
FROM ( SELECT xh,kqh as djrkqh,bm,xm,zw,lb,zy from daxx where bm='''+'安监处'+''') as daxx
order by xh '
--print @str --select * from dksr
exec (@str)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- SELECT * FROM zbkh update zbkh set je=10
ALTER procedure P_AJCqtzbKHtj -- EXEC P_AJCqtzbKHtj '2001-01-01','2009-01-01'
@daks varchar(30),
@dajs varchar(30)
as
DECLARE @LX VARCHAR(30)
declare @str varchar(4000)
set @str='SELECT xh 受奖人编号, xm 受奖人姓名, djrKQH 卡号, zw 职务, lb 人员类别 '
DECLARE CR CURSOR FOR
SELECT LX from AJCqtzb ORDER BY ID
OPEN CR
FETCH NEXT FROM CR INTO @LX
while (@@fetch_status=0)
BEGIN
SET @STR=@STR + ',(SELECT COUNT(WGBH) FROM zbkh
WHERE WGLX=''' + @LX +''' AND WGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') AS '''+@LX +''''
--------------------------------------------------------------
FETCH NEXT FROM CR INTO @LX
END
CLOSE CR
DEALLOCATE CR
SET @STR=@STR+', (SELECT SUM(WGKF) FROM zbkh
WHERE WGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') 分值合计
, (SELECT SUM(je) FROM zbkh
WHERE WGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') 奖励合计
FROM ( SELECT xh,kqh as djrkqh,bm,xm,zw,lb,zy from daxx where bm='''+'安监处'+''') as daxx
order by xh '
--print @str --select * from dksr
exec (@str)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
ALTER procedure P_AjCgrzbhz -- select * from swsr where jf<>0 and djrkqh='1497' group by wglx
@daks varchar(30),
@dajs varchar(30)
as
declare @str1 varchar(4000)
set @str1='SELECT xh 人员编号,bm 部门名称,
xm 姓名,
djrKQH 卡号,
zw 职务,
lb 人员类别 ,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx in ('''+'三违'+''','''+'违章作业'+''','''+'违章指挥'+''','''+'违犯纪律'+''') and
wgcd='+'''一般'''+' and DJRKQH=DAXX.DJRKQH ) 一般,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx in ('''+'三违'+''','''+'违章作业'+''','''+'违章指挥'+''','''+'违犯纪律'+''')
and wgcd='+'''严重'''+' and DJRKQH=DAXX.DJRKQH ) 严重,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx in ('''+'三违'+''','''+'违章作业'+''','''+'违章指挥'+''','''+'违犯纪律'+''') and
wgcd='+'''典型严违'''+' and DJRKQH=DAXX.DJRKQH ) 典型,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and (wglx='+'''军事化管理'''+' or wglx='+'''军管'''+' ) and DJRKQH=DAXX.DJRKQH) 军管 ,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx='+'''A卡'''+' and DJRKQH=DAXX.DJRKQH) A卡,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx='+'''五级隐患'''+' and DJRKQH=DAXX.DJRKQH) 五级隐患,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx='+'''隐患联责'''+' and DJRKQH=DAXX.DJRKQH ) 隐患联责,
(SELECT COUNT(distinct SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx='+'''停止作业'''+' and DJRKQH=DAXX.DJRKQH ) 停止作业,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx='+'''信息处罚'''+' and DJRKQH=DAXX.DJRKQH ) 信息处罚,
(SELECT COUNT(SWBH) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and wglx='+'''其它'''+' and DJRKQH=DAXX.DJRKQH ) 其它,
(SELECT COUNT(dkbh) FROM dksr WHERE rq>=''' +@daks +''' and rq<='''+@dajs +
''' and dksr.KQH=DAXX.DJRKQH ) D卡,
(SELECT sum(fkje) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and DJRKQH=DAXX.DJRKQH and fkje is not null) 罚款金额,
(SELECT sum(jf) FROM SWSR WHERE wzrq>=''' +@daks +''' and wzrq<='''+@dajs +
''' and DJRKQH=DAXX.DJRKQH and jf is not null) 指标加分
FROM ( SELECT xh,kqh as djrkqh,bm,xm,zw,lb,zy from daxx where bm='''+'安监处'+''') as daxx
order by xh '
exec (@str1)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- SELECT * FROM WGSR
ALTER procedure P_AJCWGKHzb -- EXEC P_AJCWGKHTJ '2001-01-01','2009-01-01'
@daks varchar(30),
@dajs varchar(30)
as
DECLARE @LX VARCHAR(30)
declare @str varchar(4000)
set @str='SELECT xh 人员编号, xm 姓名, djrKQH 卡号, zw 职务, lb 人员类别 '
DECLARE CR CURSOR FOR
SELECT LX from AJCWGLX ORDER BY ID
OPEN CR
FETCH NEXT FROM CR INTO @LX
while (@@fetch_status=0)
BEGIN
SET @STR=@STR + ',(SELECT COUNT(WGBH) FROM WGSR
WHERE WGLX=''' + @LX +''' AND zWGRKH=DAXX.DJRKQH
AND wGrq>=''' +@daks +''' and wGrq<='''+@dajs +''') AS '''+@LX +''''
--------------------------------------------------------------
FETCH NEXT FROM CR INTO @LX
END
CLOSE CR
DEALLOCATE CR
SET @STR=@STR+'
FROM ( SELECT xh,kqh as djrkqh,bm,xm,zw,lb,zy from daxx where bm='''+'安监处'+''') as daxx
order by xh '
--print @str --select * from dksr
exec (@str)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO