日期:2014-05-17 浏览次数:20911 次
CREATE FUNCTION [dbo].[FINDEVENTMES2]
(
@eventlevelcode int,
@eventtypecode varchar(50)
)
RETURNS TABLE
AS
RETURN select dutyorg, COUNTNUM
from (
(select dutyorg, count(eventid) as COUNTNUM
from dg_event
where eventtypecode like @eventtypecode and eventlevelcode = @eventlevelcode
group by dutyorg)
as b
left join
(select [JGDM],[JGMC]
FROM [table2]
where SJJGDM like '1300[123456]')
as a
on a.JGDM = b.dutyorg)
ALTER PROCEDURE [dbo].[tj_DG_EVENTBYDQ]
-- Add the parameters for the stored procedure here
@BEGINTIME DATETIME,
@ENDTIME DATETIME
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
select a.JGDM,a.JGMC,
isnull(n.COUNTNUM,0) as zrzh_1, isnull(m.COUNTNUM,0) as zrzh_2, isnull(o.COUNTNUM,0) as zrzh_3, isnull(p.COUNTNUM,0) as zrzh_4,
isnull(u.COUNTNUM,0) as sgzn_1,isnull(b.COUNTNUM,0) as sgzn_2,isnull(c.COUNTNUM,0) as sgzn_3,isnull(d.COUNTNUM,0) as sgzn_4,
isnull(e.COUNTNUM,0) as shws_1,isnull(f.COUNTNUM,0) as shws_2,isnull(g.COUNTNUM,0) as shws_3,isnull(h.COUNTNUM,0) as shws_4,
isnull(i.COUNTNUM,0) as shgg_1,isnull(j.COUNTNUM,0) as shgg_2,isnull(k.COUNTNUM,0) as shgg_3,isnull(l.COUNTNUM,0) as shgg_4,
isnull(q.COUNTNUM,0) as qt_1,isnull(r.COUNTNUM,0) as qt_2,isnull(s.COUNTNUM,0) as qt_3,isnull(t.COUNTNUM,0) as qt_4
from ((select JGDM,JGMC from table2 where SJJGDM like '1300[123456]') as a
left join FINDEVENTMES2(2,'12%') as b on a.[JGDM] = b.dutyorg
left join FINDEVENTMES2(3,'12%') as c on a.[JGDM] = c.dutyorg
left join FINDEVENTMES2(4,'12%') as d on a.[JGDM] = d.dutyorg
left join FINDEVENTMES2(1,'13%') as e on a.[JGDM] = e.dutyorg
left join FINDEVENTMES2(2,'13%') as f on a.[JGDM] = f.dutyorg
left join FINDEVENTMES2(3,'13%') as g on a.[JGDM] = g.dutyorg
left join FINDEVENTMES2(4,'13%') as h on a.[JGDM] = h.dutyorg
left join FINDEVENTMES2(1,'14%') as i on a.[JGDM] = i.dutyorg
left join FINDEVENTMES2(2,'14%') as j on a.[JGDM] = j.dutyorg
left join FINDEVENTMES2(3,'14%') as k on a.[JGDM] = k.dutyorg
left&n