IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[weixintb]') AND type = 'V')
DROP VIEW [dbo].[weixintb]
GO
CREATE VIEW dbo.weixintb
AS
SELECT     dp_id,dp_level,dp_depart,dp_fdpid,dp_bcid,dp_order
FROM         mps_depart
WHERE     dp_note != '加盟门店' AND dp_note != '直营门店'
UNION
SELECT     100000001, 1, '直营店铺', 244, 13, 2
UNION
SELECT     100000000, 1, '加盟店铺', 244, 13, 1
UNION
SELECT    dp_id,dp_level+1,dp_depart,100000001 as dp_fdpid,dp_bcid,dp_order 
FROM         mps_depart
WHERE     dp_note = '直营门店'
UNION
SELECT      dp_id,dp_level+1,dp_depart,100000000 as dp_fdpid ,dp_bcid,dp_order
FROM         mps_depart
WHERE     dp_note = '加盟门店'