(
@idcard nvarchar(50)='-1',
@username nvarchar(50)='-1',
@serialnumber nvarchar(50)='-1',
@usertype int=-1,
@userstatus int=-1,
@addtime1 nvarchar(50)='1900-01-01',
@addtime2 nvarchar(50)='2900-01-01',
@pageindex int=1,
@pagesize int=15,
@mycount int=0 OUT )
declare @sql nvarchar(2000)
declare @sql_count nvarchar(2000)
set @sql='select top '+CAST(@pagesize as varchar(32))+' * from userinfo where 1>0'
set @sql_count='update [user] set wanttoread=1 where 1>0'
if @idcard<>'-1'
begin
set @sql=@sql+' and idcard like ''%'+CAST( @idcard as nvarchar)+'%'''
set @sql_count=@sql_count+' and idcard like ''%'+CAST( @idcard as nvarchar)+'%'''
end
if @username<>'-1'
begin
set @sql=@sql+' and username like ''%'+CAST( @username as nvarchar)+'%'''
set @sql_count=@sql_count+' and username like ''%'+CAST( @username as nvarchar)+'%'''
end
if @serialnumber<>'-1'
begin
set @sql=@sql+' and serialnumber like ''%'+CAST( @serialnumber as nvarchar)+'%'''
set @sql_count=@sql_count+' and serialnumber like ''%'+CAST( @serialnumber as nvarchar)+'%'''
end
if @usertype<>-1
begin
set @sql=@sql+' and usertype_id='+CAST(@usertype as nvarchar)
set @sql_count=@sql_count+' and usertype='+CAST(@usertype as nvarchar)
end
if @userstatus<>-1
begin
set @sql=@sql+' and userstatusid='+CAST(@userstatus as nvarchar)
set @sql_count=@sql_count+' and status='+CAST(@userstatus as nvarchar)
end
if @addtime1<>'-1' and @addtime2<>'-1'
begin
set @sql=@sql+' and addtime>'''+CONVERT(varchar(50
),@addtime1,120)+''' and addtime<'''+CONVERT(varchar(50),@addtime2,120)+''''
set @sql_count=@sql_count+' and addtime>'''+CONVERT(varchar(50
),@addtime1,120)+''' and addtime<'''+CONVERT(varchar(50),@addtime2,120)+''''
end
exec(@sql_count)
set @mycount= @@rowcount
set @sql=@sql+' and addtime not in (select top '+CAST((@pagesize*(@pageindex-1)) as varchar(32))+ ' addtime from userinfo where 1>0'
if @idcard<>'-1'
begin
set @sql=@sql+' and idcard like ''%'+CAST( @idcard as nvarchar)+'%'''
end
if @username<>'-1'
begin
set @sql=@sql+' and username like ''%'+CAST( @username as nvarchar)+'%'''
end
if @serialnumber<>'-1' begin