IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[proj_qsy_get_consult_history]') AND type = 'P')
DROP PROCEDURE [dbo].[proj_qsy_get_consult_history]
GO

-- =============================================
-- Author:<00384>
-- Create date: <2018-06-28>
-- Description:<呼叫中心-获取咨询单历史>
-- =============================================
CREATE PROCEDURE [dbo].[proj_qsy_get_consult_history] 
-- Add the parameters for the stored procedure here
@pagesize int,
@pagecount int ,
@pageobjids varchar(max),
@mobileNo nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

declare @s1 varchar(8000),
@s2 varchar(100),
@IDs varchar(max)='',
@i int,
@amount int

declare @pobjs table(nid int identity(1, 1), ordid bigint) 
select @amount = @pagecount*@pagesize

set @s1 = @pageobjids

while (@s1>'')
begin
set @i = charindex(',', @s1)
if (@i>0)
begin
set @s2 = substring(@s1,1,@i-1)
set @s1 = substring(@s1,@i+1,len(@s1)-@i)
end else
begin
set @s2 = @s1
set @s1 = ''
end
if(@IDs>'') 
set @IDs = @IDs +','+@s2
else 
set @IDs = @s2

insert into @pobjs(ordid) values(convert(bigint,@s2)) 
end
if (exists (select top 1 * from @pobjs) )
begin
select * from order_86,@pobjs
where ord_lxdh =@mobileNo
and ord_id = ordid

return
end

---以下是第一次加载数据
select COUNT(ord_id) cnt from order_86
where ord_lxdh =@mobileNo

select top(@pagesize) ord_id from order_86
where ord_lxdh =@mobileNo
order by ord_id desc 

select top(@amount) * from order_86
where ord_lxdh =@mobileNo
order by ord_id desc 



END