IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_mobilestateinfo]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_mobilestateinfo]
GO
-- =============================================    
-- Author:  郑华建    
-- Create date: 2018年1月8日 12点59分    
-- Description: 根据state获取state对应的微信app,和对应的url    
-- =============================================    
CREATE PROCEDURE [dbo].[mps_g_mobilestateinfo]    
@state varchar(128)    
AS    
BEGIN    
 SET NOCOUNT ON;    
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
 declare @index int    
 declare @type varchar(10)    
 declare @shareId varchar(10)    
 --先提取type    
 set @index=CHARINDEX('.',@state)    
 set @type=SUBSTRING(@state,1,@index-1);    
 set @state=SUBSTRING(@state,@index+1,LEN(@state));    
 --提取基本的state,和shareId    
 set @index=CHARINDEX('_',@state)    
 if(@index>0)    
 begin    
  set @shareId=SUBSTRING(@state,@index+2,LEN(@state));    
  set @state=SUBSTRING(@state,1,@index-1);    
 end    
 --select @type,@state,@shareId    
 --返回账号信息,和跳转的链接信息    
 select wxs_id,wx_code,wx_type,wx_code+wx_appsecret+CONVERT(varchar,wx_appid) as wx_key,    
 case when @shareId is null then wxs_value else (select top 1 ms_url from mps_mobileshare with(nolock)  where ms_id=@shareId) end as wxs_value    
 from mps_weixinstate with(nolock) ,ebs_kernel.dbo.pub_weixin     with(nolock) 
 where wx_id= case when @type='qyh' then wxs_qyh     
 else case when @type='gzh' then wxs_gzh    
 else case when @type='ding' then wxs_ding    
 end end end and wxs_code=@state    
END