declare @Caller nvarchar(50) set @Caller='15670605766' declare @locationID int--主叫号码的归属地ID declare @areacode nvarchar(50)--区号 declare @usercode nvarchar(50)--需要返回的坐席 declare @zxzid int --坐席组ID --处理主叫号码 获取手机号码前7位 declare @first char(5) declare @Top7 char(10) set @first=LEFT(@Caller, 1); if @first='0' begin set @Top7=SubString(@Caller, 2,7); end else begin set @Top7=SubString(@Caller, 1,7); end --根据前7位获取区号 select @areacode=F_ZipCode FROM T_Sys_MobileData where F_MobileNum=@Top7 --根据区号获取地区ID select @locationID=id FROM tel_location where tel=@areacode --根据地区ID获取对应负责的坐席组ID select @zxzid=userid from telloc_users where tellocid=@locationID select @zxzid,@first,@Top7,@areacode