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语句 请大家帮帮忙把 下午就要了~

解决方案 »

  1.   

    问题就是不能前端解决 只能在后面加IF判断 而且这个SQL查询会影响到很多地方 急死人啊
      

  2.   

    in後面3600個數據,這個SQL語句好像也太那個了吧,為什麼要分1000,1000的呢?
      

  3.   

    “没有看懂”  受打击了
    就是他IN后面的那个条件 可能是个很大的数据 超过1000条
    现在就是感觉象HIBERNATE里的分页 把他分成1000条一页的情况 
    我这用的是JDBC连的
      

  4.   

    1. 获取总条数 3600
    2. 3600/1000 得出 4
    3. page 属性制定要那页  2 ,pagesize = 1000;
    4. 然后 将 数据集后移 2* pagesize ,再获取 pagesize条数据即可
      

  5.   

    在这里先谢谢大家踊跃回复 我不会浪费大家的心意的现在公司就让我直接在IN后面加判断 如果用程序做分页控制我会
    但在SQL里 不大会 如果能在 SQL中做分页 会不会很麻烦 怎么弄 请大家指教
      

  6.   

    shawnwan() 
    说的对的 我也是这样想的 但是怎样才能写出SQL语句呢 SQL我一点都不好 只会基本的
      

  7.   

    http://community.csdn.net/Expert/topic/4917/4917705.xml?temp=.6137964
    分页存储过程,你参考一下
      

  8.   

    THANKS 不晓得 会不会来 有问题在来请教 问题解决 马上结贴 大家都有分
      

  9.   

    请楼主先测试一下这个存储过程的结果是否符合要求:
    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
      

  10.   

    不知道hellowork(一两清风) 是不是这个意思select IDD=identity(int,1,1),* into #t  from table
    select * from #T Where IDD Between 2000 And 3000
    Drop table #T
      

  11.   

    对啊,可能楼主的表里没有id,那么就要使用你上面写的方法生成id,这样才能应用我上面那个方法.