IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_category_cstinfo]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_category_cstinfo]
GO
CREATE procedure [dbo].[mps_g_category_cstinfo](
@cmpid int,
@useruid int,
@useradmin int ,
@cctag int  
)
as
begin
set nocount on 
declare @biztype varchar(30) 
set @biztype = 'csttag' 

select * from mps_template where tmp_cmpid=@cmpid and tmp_type=@biztype and tmp_objid=@cctag and 
(tmp_objid2=@useradmin or tmp_objid2=0)    order by tmp_objid2 desc 
-- 获取有之相关的所有业务单信息
 
declare @t table(bizid int , ok int) 
insert into @t(bizid,ok) 
select ct_id ,0
from mps_csttype  
where ct_cmpid=@cmpid and ct_tag=@cctag 
    
    update @t set ok=1 
    from mps_csttype_users 
    where cp_ctid=bizid and cp_cuid=@useruid and 
(cp_type='cstaudit' or cp_type='cstabolish' or cp_type='cstdelete' or cp_type='cstnew' or cp_type='cstview' )

select distinct ct_order biz_order,ct_id biz_id,0 biz_formstyle,1 biz_hidemenu,
ct_icon biz_icon,ct_type biz_title, ct_caption biz_category , 0 biz_subcategory  , 0 biz_comefrom  
from mps_csttype , @t 
where ct_id=bizid and ok=1 
order by ct_order 

set nocount off 
end