SQL中没有记录号的概念,无法直接取得记录号,只有用下列方法!
Select RecordID=identity(int,1,1),* into #tt from table1
Select * from #tt
Drop table #tt

解决方案 »

  1.   

    给你个思路(引用    zjcxc(邹建) 的回答)用一条语句选出分数排名第5到第7的学生,最好还要是能写成存储过程,比如从N->M的排名
    create proc p_qry
    @n int=5,
    @m int=7
    as
    select *
    from [table] a
    where (
    select count(distinct score) from [table]
    where score>=a.score
    )between @n and @m
      

  2.   

    select count(1) from 表 where 主键<需要查询位置的记录的主键字段的值
      

  3.   

    select lpad(SPF01_back.nextval,8,''0'') from dual
    什么意思
      

  4.   

    select count(1) from 表 where 主键<需要查询位置的记录的主键字段的值
    不好吗?
      

  5.   

    升序排名
    select *,count(*)+1 排名 from table a join table b on a.id列=b.id列 where a.排名列<b.排名列 and (该记录的选择条件)降序排名
    select *,count(*)+1 排名 from table a join table b on a.id列=b.id列 where a.排名列>b.排名列 and (该记录的选择条件)
      

  6.   

    --创建调试环境
    if object_id('tbl_t') is null
    print 'not exists'
    else
    drop table tbl_t
    create table tbl_t
    (
    aa varchar(20),
    bb varchar(20)
    )insert into tbl_t values('a1','b1')
    insert into tbl_t values('a2','b2')
    insert into tbl_t values('a3','b3')
    insert into tbl_t values('a4','b4')
    select * from (select tmpid=identity(int,1,1),* into #tmp from tbl_t)t
    select tmpid 行号 from  #tmp where aa='a4'--删除表
    drop table tbl_t
    --结果:
    /*
    tmpid       
    ----------- 
    4(所影响的行数为 1 行)
    */
      

  7.   

    select * from (select tmpid=identity(int,1,1),* into #tmp from tbl_t)t
    --->
    select tmpid=identity(int,1,1),* into #tmp from tbl_t
      

  8.   

    不太了解你要干什么?你的意思是找到一条记录,然后返回这个记录在原表的的位置是吗?如果是的话。你这么做。你把这个记录的主键找到赋值给一个变量a。然后这么写:
    adodc1.recordset.movefirst 
    if adodc1.recordset.fields(0).value=a then
    i=1
    debug.printf a
    else 
    adodc1.recordset.movenext
    i=i+1
    debug.printf a
    endif