IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_shopmenu]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_shopmenu]
GO


--查询菜单的方式
--存储过程
create proc [dbo].[mps_g_shopmenu]
@cmpid bigint,
@model bigint,
@bcid bigint
as
begin
set nocount on
if @model=1
begin
select distinct dp_province+'/'+dp_municipal+CASE 
WHEN dp_county = '' THEN '' else '/'+dp_county END AS area,dp_province as id
from mps_depart where dp_isdepart  = 1 and dp_cmpid= @cmpid and dp_province>''  and (@bcid=0 or dp_bcid=@bcid)
order by area
end else
if @model= 2
begin
select distinct dp_note as area , dp_note as id
from mps_depart where dp_isdepart  = 1 and dp_cmpid= @cmpid and (@bcid=0 or dp_bcid=@bcid)
end else 
if @model = 3
begin
select distinct dp_managearea as area, dp_managearea as id
from mps_depart where dp_isdepart  = 1 and dp_cmpid= @cmpid and (@bcid=0 or dp_bcid=@bcid)
end else 
if @model = 4
begin
select distinct dp_category1+CASE 
WHEN dp_category2 = '' THEN '' else '/'+dp_category2+CASE 
WHEN dp_category3 = '' THEN '' else '/'+dp_category3 end
END AS area,dp_category1 from mps_depart 
where dp_isdepart  = 1 and dp_cmpid= @cmpid and dp_category1>''  and (@bcid=0 or dp_bcid=@bcid)
order by area
end
set nocount off
end