if exists(select 1 from sysobjects where name='pr_wxsf_vip_status_query')
  drop procedure pr_wxsf_vip_status_query
go


--功能:查询会员状态  0-不存在会员；1-存在会员但未绑定营销员；2-存在会员且已经绑定营销员
create proc pr_wxsf_vip_status_query 
(  
	@card_id	 varchar(20) --会员卡ID
)
as
begin
	set nocount on --

	declare @ls_status	varchar(1), 
			@ll_count	int,
			@ll_count1	int  
	
	set @card_id = LTRIM(RTRIM(@card_id)) 

	select @ll_count = isnull(count(1),0) from t_rm_vip_info with(nolock) where card_id like @card_id 
	if @ll_count <= 0
	begin 
		set @ls_status = '0'
	end
	else
	begin 
		select @ll_count1 = isnull(count(1),0) from t_rm_vip_info v with(nolock),t_rm_saleman s with(nolock)
			where v.oper_id = s.sale_id and v.card_id like @card_id and isnull(v.oper_id,'')<>''
		if @ll_count1 > 0 
			set @ls_status = '2'
		else
			set @ls_status = '1'
	end	

	select @ls_status as status
	
	set nocount off --
end
go