IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_all_resources]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_all_resources]
GO
CREATE procedure [dbo].[mps_g_all_resources] 
@cmpid int 
as
begin
  set nocount on
  -- 首先返回业务单
  select 0 as order1 ,'biz' rsctype , case when biz_subcategory>'' then biz_category+'/'+biz_subcategory else biz_category end rsctitle , biz_title rsccaption , biz_id rscid 
   from mps_biztype   where biz_cmpid=@cmpid  and biz_status>=0 
union   
  -- 返回客户
  select distinct 1 as order1 , 'cst' rsctype , '客户类资源' as rsctitle,  ct_caption rsccaption , ct_tag rscid  from mps_csttype  where ct_cmpid=@cmpid 
  union   
  -- 返回产品
  select distinct 2 as order1 , 'prd' rsctype ,'产品（物料）类资源' as rsctitle, pc_caption rsccaption , pc_tag rscid  from mps_prdctg  where pc_cmpid=@cmpid 
  union   
  -- 返回设备
  select distinct 3 as order1 ,'equ' rsctype , '设备类资源' as rsctitle,ec_caption rsccaption , ec_tag rscid  from mps_equctg  where ec_cmpid=@cmpid 
  union   
  -- 返回文档
  select distinct 4 as order1 , 'doc' rsctype ,'文档类资源' as rsctitle, dc_caption rsccaption , dc_tag rscid  from mps_docctg  where dc_cmpid=@cmpid 
  union   
  -- 获取扩展资源 
  select  5 as order1 ,etc_type rsctype ,'用户扩展类资源' as rsctitle,etc_caption rsccaption , 0 rscid   from mps_ext_resource where  etc_cmpid=@cmpid 
  order by order1,rsctitle,rscid  
  set nocount off
end