IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[Qsy_cc_desk_vipinfo]') AND type = 'P')
DROP PROCEDURE [dbo].[Qsy_cc_desk_vipinfo]
GO
-- =============================================
-- Author:<00384>
-- Create date: <2018-06-28>
-- Description:<呼叫中心-VIP基础资料查询>
-- =============================================
CREATE PROCEDURE [dbo].[Qsy_cc_desk_vipinfo] 
-- Add the parameters for the stored procedure here
@pagesize int,
@pagecount int ,
@tel nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

--VIP卡资料
--select * from openquery(posformal,'select v.id,v.CARDNO,t.NAME  VIPTYPE,
--f.name shopname,f.pq,f.fz,f.zj,f.jl,f.zg dd,f.dz,f.dpfzr
--from C_VIP v
--join C_VIPTYPE t on  v.C_VIPTYPE_ID=t.id
--join fzh_v_storeinfoall f on f.id=v.C_STORE_ID
--where v.MOBIL=''15008216258''  and v.ISACTIVE=''Y'' and v.VIPACTIVE=''Y'' and v.VIPSTATE=''Y''  ')

--set @tel='15008216258'

SET NOCOUNT ON;


declare @sql nvarchar(max)

set @sql='


select * from openquery(posformal,''select count(v.id) as cnt
from C_VIP v
join C_VIPTYPE t on  v.C_VIPTYPE_ID=t.id
join fzh_v_storeinfoall f on f.id=v.C_STORE_ID
where v.MOBIL='''''+@tel+'''''  and v.ISACTIVE=''''Y'''' and v.VIPACTIVE=''''Y'''' and v.VIPSTATE=''''Y''''  '')


select id from openquery(posformal,''select v.id 
from C_VIP v
join C_VIPTYPE t on  v.C_VIPTYPE_ID=t.id
join fzh_v_storeinfoall f on f.id=v.C_STORE_ID
where v.MOBIL='''''+@tel+'''''  and v.ISACTIVE=''''Y'''' and v.VIPACTIVE=''''Y'''' and v.VIPSTATE=''''Y''''  '')


select * from openquery(posformal,''select v.id,v.VIPNAME,v.CARDNO,t.NAME  VIPTYPE,v.INTEGRAL jf,
f.name shopname,f.pq,f.fz,f.zj,f.jl,f.zg dd,f.dz,f.dpfzr
from C_VIP v
join C_VIPTYPE t on  v.C_VIPTYPE_ID=t.id
join fzh_v_storeinfoall f on f.id=v.C_STORE_ID
where v.MOBIL='''''+@tel+'''''  and v.ISACTIVE=''''Y'''' and v.VIPACTIVE=''''Y'''' and v.VIPSTATE=''''Y''''  '')
' 

exec (@sql)

set nocount off

END