USE [CallCenter_XinXiangXLX]
GO
/****** Object:  StoredProcedure [dbo].[P_GetZBDH]    Script Date: 08/09/2019 13:51:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[P_GetZBDH] 
(
  @callee NVARCHAR(50) -- 被叫号码
)
AS
BEGIN
	
	SET NOCOUNT ON;
	declare @zbdh varchar(50)
	declare @zbid int
	declare @groupcode nvarchar(50) --坐席组编号
	
	if @Callee='9100'
	begin
		set @groupcode='XLXKFZ'--心连心客服组
	end
	else if @Callee='9101'
	begin
		set @groupcode='NXKFZ'--农心客服组-手拉手
	end
	else if @Callee='9102'
	begin
		set @groupcode='NXKFZ' --农心客服组-沃利沃
	end
	else if @Callee='9300'
	begin
		set @groupcode='XJKFZ' --新疆心连心客服组
	end
	else if @Callee='9200'
	begin
		set @groupcode='JJKFZ'--九江心连心客服组
	end
	else
	begin
		set @groupcode='XLXKFZ'--默认心连心
	end
	
	
	select Top 1 @zbdh=F_ZBDH,@zbid=F_ZBID from T_Call_ZBDH where F_GroupName=@groupcode	 order by F_CallinTime,F_ZBID	
	
	update T_Call_ZBDH set F_CallinTime=GETDATE() where F_ZBID=@zbid 
	   
	select @zbdh
END

