很久沒寫儲存過程,今天寫個儲存下

2021-09-24 03:47:20 字數 3885 閱讀 1298

goset ansi_nulls on

goif   exists   (select   *  from   dbo.sysobjects  

where   id=object_id(n'[dbo].[p_police_binding_statistics]') 

and objectproperty(id,   n'isprocedure') =  1)    

drop   procedure   [dbo].[p_police_binding_statistics]    

go  

set quoted_identifier on

go/*add 20190604 xqy 警員繫結統計*/

create proc [dbo].[p_police_binding_statistics] 

@orgno varchar(40) , --組織機構**

@roleid nvarchar(100)=null --角色id

asdeclare @r varchar(12) ='';

set @r=dbo.earsezero(@orgno);

--二級組織機構集合 #t_org

declare @id int;

select @id=id from  t_organization where orgno=@orgno and isdel=0

select dbo.earsezero(orgno) as org,orgno,showname as shortname,orgname

into #t_org

from t_organization where (pid=@id or id=@id) and isdel=0

order by org

--警員總數

select count(uid) as jyzs,gajgdm,dbo.earsezero(gajgdm) as gajgdm_n 

into #jyzs from t_user 

where (@roleid is null or uid in (select uid from t_userrole where rid=@roleid))

and  (@orgno is  null or  gajgdm like ''+@r+'%') 

group by gajgdm

--申請數

select  count(ppid) as weixintotal,u.gajgdm,dbo.earsezero(gajgdm) as gajgdm_n1 

into #sqs 

from t_policeprove p join t_user u  on p.policeid=u.jh  

where (@roleid is null or uid in (select uid from t_userrole where rid=@roleid))

and  (@orgno is  null   or  gajgdm like ''+@r+'%') 

group by gajgdm

--實名認證數

select  count(ppid) as name_authentication,u.gajgdm,dbo.earsezero(gajgdm) as gajgdm_n2  

into #smrzs

from t_policeprove p join t_user u  on p.policeid=u.jh 

where (@roleid is null or uid in (select uid from t_userrole where rid=@roleid))

and  (@orgno is  null   or  gajgdm like ''+@r+'%') 

and status=1 group by gajgdm

--近7天訪問總數

select count(id) as visit7day,workunit,dbo.earsezero(workunit) as gajgdm_n3  

into #7tfwzs

from t_log  l join t_user u on l.userid=u.uid   

where datediff(dd,operationtime,getdate())<=7  

and operationaction='150112' and  workunit is not null  

and (@roleid is null or uid in (select uid from t_userrole where rid=@roleid))

and  (@orgno is  null   or  gajgdm like ''+@r+'%') 

group by workunit

--組織機構和警員總數聯合

select a.org,a.orgno,a.orgname,sum(jyzs)jyzs  into  #result1 from #t_org a join #jyzs b on a.org=b.gajgdm_n group by a.org,a.orgno,a.orgname;

--select * from #result1;

--組織機構和申請數,有疑問,多了

select c.org,c.orgno,c.orgname,sum(weixintotal)weixintotal  into  #result2 from #t_org c join #sqs d on c.org=d.gajgdm_n1 group by c.org,c.orgno,c.orgname;

--select * from #result2;

--組織機構和實名認證數

select e.org,e.orgno,e.orgname,sum(name_authentication)name_authentication  into  #result3 from #t_org e join #smrzs f on e.org=f.gajgdm_n2 group by e.org,e.orgno,e.orgname;

--select * from #result3;

--組織機構和近七天訪問數

select g.org,g.orgno,g.orgname,sum(visit7day)visit7day  into  #result4 from #t_org g join #7tfwzs h on g.org=h.gajgdm_n3 group by g.org,g.orgno,g.orgname;

--select * from #result4;

--組織機構

--jyzs 是警員總數

--weixintotal 是申請數

--name_authentication 是實名認證數

--wsqs 是未申請數 未申請數=申請數-實名認證數

--visit7day 是近七天訪問數

select a1.*, 

isnull(jyzs,0) jyzs,isnull(weixintotal,0)weixintotal,isnull(name_authentication,0)name_authentication,isnull(visit7day,0)visit7day

--jyzs,weixintotal,name_authentication,visit7day

,isnull(weixintotal-name_authentication,0)wsqs

from #t_org a1 

left join #result1 b1 on a1.orgno=b1.orgno

left join  #result2 b2  on a1.orgno=b2.orgno

left join  #result3 b3  on a1.orgno=b3.orgno

left join  #result4 b4  on a1.orgno=b4.orgno

又很久沒寫東西了。。。

又很久沒寫點東西了。理由當然是很忙。有空的時候就貓在機房,做做不完的事情。現在的生活學習似乎徹底e化了。每天開郵箱掛qq處理日常事務。然後是看google日曆察看或安排日程。如果有課就要上網路學堂看有什麼課件,有什麼通知。下了課還有上學堂看作業,接著開始用word,latex趕作業,提交到學堂上。人...

很久沒做夢了

感覺很奇異,好多事情都沒聯絡。內容簡單記一下。1.路過一地,看樣子是建設到一半被廢棄了的商業區,遇到了一場騷亂,途中邂逅一女。2.到此女家,門居然是個牆上的洞,還帶蜘蛛網,網後面有乙隻很大個的馬蜂在空中盤旋並不時從尾巴向外噴毒液 貌似就是mh2g裡的王蜂?3.進到裡面,木質布置,燈光昏暗。見到了此女...

很久沒有寫log了

很久了吧,很長時間沒上網了。不過以後上網時間會很多。這樣看書的時間少了很多。我也不知道該怎麼辦。看了freer的blog,感覺有人出了問題 下面簡單記下培訓情況。2號去的南京,二人一間屋,條件很好,電視 空調 衛生間一應俱全。65號人,江蘇和安徽的。我被指派做了第三組的組長。第一組,合肥中支15人,...