IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_pick_menutype]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_pick_menutype]
GO
create proc [dbo].[mps_g_pick_menutype]
@cmpid int,
@mtype varchar(100)
as
begin
set nocount on

if(@mtype='biz')
begin
select distinct case when biz_subcategory='' then biz_category+'/'+biz_title else biz_category+'/'+biz_subcategory+'/'+biz_title end as content ,
biz_category as category,biz_subcategory as subcategory,biz_order as morder,biz_id as id ,biz_id as tag
from mps_biztype where biz_cmpid=@cmpid and biz_status>=0 order by biz_order asc
end else
if(@mtype='cst')
begin
select  distinct ct_caption+'/'+ct_type as content,
ct_caption as category,ct_type as  subcategory,ct_order as morder, ct_id as id,ct_tag as tag
from mps_csttype
where ct_type > '' and ct_caption > ''
order by ct_order 
end else
if(@mtype='prd')
begin

select  distinct pc_caption+'/'+pc_full as content,
pc_caption as category,pc_caption as  subcategory,pc_order as morder, pc_id as id,pc_tag as tag
from mps_prdctg
where pc_type > ''  and pc_full >''
order by pc_order
end
else
if(@mtype='doc')
begin
select  distinct dc_caption+'/'+dc_full as content,
dc_caption as category,dc_caption as  subcategory,dc_order as morder, dc_id as id,dc_tag as tag
from mps_docctg
where dc_full > '' and dc_type >'' and dc_level = 0
order by dc_order
/*select  distinct dc_caption+'/'+dc_full as content,
dc_caption as category,dc_caption as  subcategory,dc_order as morder, dc_id as id,dc_tag as tag
from mps_docctg
where dc_full > '' and dc_type >''
order by dc_order*/
end else 
if(@mtype='rpt')
begin
select distinct
case when rpt_categorysub='' then rpt_category+'/'+rpt_title 
else rpt_category+'/'+rpt_categorysub+'/'+rpt_title end as content ,
    rpt_id as id,rpt_title,rpt_category as category,rpt_categorysub as subcategory,
    rpt_order as morder, 0 as tag
from mps_report 
where rpt_title != ''
order by rpt_order
end

set nocount off
end