IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_document_hot]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_document_hot]
GO
 
create proc [dbo].[mps_g_document_hot] 
@dcid int ,
@useruid int ,
@usersecurity int ,
@branchid int,
@userdpid int,
@userotid int ,
@cmpid int
as
begin
set nocount on
declare @dc table(dcid int) 
if (@dcid>0) 
begin
insert into @dc(dcid) values(@dcid) 
end else 
begin
insert into @dc(dcid) select dc_id from mps_docctg where dc_cmpid=@cmpid and dc_tag=(-1)*@dcid 
end 
-- 将子目录加入
insert into @dc(dcid) 
select dc_id from mps_docctg , @dc 
where dc_father = dcid and 
(not exists (select 1 from @dc where dcid=dc_id))

insert into @dc(dcid) 
select dc_id from mps_docctg , @dc 
where dc_father = dcid and 
(not exists (select 1 from @dc where dcid=dc_id))

insert into @dc(dcid) 
select dc_id from mps_docctg , @dc 
where dc_father = dcid and 
(not exists (select 1 from @dc where dcid=dc_id))

insert into @dc(dcid) 
select dc_id from mps_docctg , @dc 
where dc_father = dcid and 
(not exists (select 1 from @dc where dcid=dc_id))

select top 10 a.* from mps_document a, @dc  where dcid=doc_dcid  order by doc_click desc 
select top 10 a.* from mps_document a, @dc  where dcid=doc_dcid  order by doc_like desc 

    set nocount off
end