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




-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[mps_g_wxcountbystate]
-- Add the parameters for the stored procedure here
@state varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @type varchar(50)
declare @index int
set @index=CHARINDEX('.',@state);
if(@index=0) return;
--切割字符串
set @type=SUBSTRING(@state,1,@index-1);
set @state=SUBSTRING(@state,@index+1,LEN(@state));
--select @type,@state
if(@type='qyh')
select * from mps_weixinstate,ebs_kernel.dbo.pub_weixin where wxs_code=@state and wxs_qyh=wx_id
else if(@type='gzh')
select * from mps_weixinstate,ebs_kernel.dbo.pub_weixin where wxs_code=@state and wxs_gzh=wx_id
else if(@type='ding')
select * from mps_weixinstate,ebs_kernel.dbo.pub_weixin where wxs_code=@state and wxs_ding=wx_id
END