SELECT distinct Flowfile.FileID
FROM FlowFile, WorkFlow
WHERE 0=0
and FlowFile.FlowTypeID in (<%=Cast._String(getVariable(pageContext,"Client.FlowTypes"))%>就是最后一个AND条件 FlowFile.FlowTypeID 后面IN的那个条件是网页上得过来的 但是他的数据量可能很但 现在想做的就是 不能大于1000条数据就 如果IN后面的数据有3600条 就要是 1000条 1000条 1000条 600条 这样 我的想法是这样的就是把记录取出来
然后有个@@count属性
去判断记录是多少条
然后 / 1000
分几次
然后到了1000
打回车
但是我不知道 怎么写成SQL语句 请大家帮帮忙把 下午就要了~
FROM FlowFile, WorkFlow
WHERE 0=0
and FlowFile.FlowTypeID in (<%=Cast._String(getVariable(pageContext,"Client.FlowTypes"))%>就是最后一个AND条件 FlowFile.FlowTypeID 后面IN的那个条件是网页上得过来的 但是他的数据量可能很但 现在想做的就是 不能大于1000条数据就 如果IN后面的数据有3600条 就要是 1000条 1000条 1000条 600条 这样 我的想法是这样的就是把记录取出来
然后有个@@count属性
去判断记录是多少条
然后 / 1000
分几次
然后到了1000
打回车
但是我不知道 怎么写成SQL语句 请大家帮帮忙把 下午就要了~
就是他IN后面的那个条件 可能是个很大的数据 超过1000条
现在就是感觉象HIBERNATE里的分页 把他分成1000条一页的情况
我这用的是JDBC连的
2. 3600/1000 得出 4
3. page 属性制定要那页 2 ,pagesize = 1000;
4. 然后 将 数据集后移 2* pagesize ,再获取 pagesize条数据即可
但在SQL里 不大会 如果能在 SQL中做分页 会不会很麻烦 怎么弄 请大家指教
说的对的 我也是这样想的 但是怎样才能写出SQL语句呢 SQL我一点都不好 只会基本的
分页存储过程,你参考一下
if object_id('tbtest') is not null
drop table tbtest
GO
----创建测试数据表
select top 50 id = identity(int,1,1),0 as FlowTypeID into tbtest from syscolumns
update tbtest set FlowTypeID = id*2 /*设置FlowTypeID的测试值*/
GOif object_id('spTest') is not null
drop proc spTest
GO
----创建测试存储过程
CREATE PROC spTest
@PageSize int, /*每次显示的行数*/
@FlowTypes varchar(4000) /*条件表达式.注意:本例中FlowTypeID列必须为整型.*/
as
declare @RecordCount int /*符合条件的总行数*/
declare @sql nvarchar(4000)
set @sql = 'select @RecordCount = count(*) from tbtest where 0 = 0
and FlowTypeID in (' + @FlowTypes + ')'
exec sp_executesql @sql,N'@RecordCount int output',@RecordCount output
declare @str varchar(8000)
declare @i int
set @str = ''
set @i = 0
while @RecordCount/@PageSize >= 1
begin
set @str = @str + '
select top ' + cast(@PageSize as varchar(10)) + ' * from tbtest
where 0 = 0 and FlowTypeID in (' + @FlowTypes + ')
and id not in(select top ' + cast(@i*@PageSize as varchar(10)) + ' id from tbtest
where 0 = 0 and FlowTypeID in (' + @FlowTypes + '))'
set @i = @i + 1
set @RecordCount = @RecordCount - @PageSize
end
set @str = @str + '
select top ' + cast(@PageSize as varchar(10)) + ' * from tbtest
where 0 = 0 and FlowTypeID in (' + @FlowTypes + ')
and id not in(select top ' + cast(@i*@PageSize as varchar(10)) + ' id from tbtest
where 0 = 0 and FlowTypeID in (' + @FlowTypes + '))'
print @str
EXEC(@str)
GO
----执行存储过程
----客户端使用ADO接收时使用RecordSet.NextRecordSet方法逐个接收返回的记录集,
----每次调用该方法后然后判断RecordSet.Sate是否等于adStateClosed.
EXEC sptest 3,'2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32'----清除测试环境
drop proc spTest
drop table tbTest
select * from #T Where IDD Between 2000 And 3000
Drop table #T