CREATE PROCEDURE p_GetKeyID
    @N int
    @IDN int OUTPUT
AS
select identity(1,1) tid,t.id into #t from table1 t order by id desc
select @IDN=id from #t where tid=@n
go

解决方案 »

  1.   

    CREATE PROCEDURE p_GetKeyID
        (@N int,
        @IDN int OUTPUT)
    AS
    set rowcount @N
    select * into #t from table1 order by id desc
    select top 1 @IDN = IDN from #t order by id
    set rowcount 0
    drop table #tGO
      

  2.   


    Select @IDN = id from table1 a where (select count(*) from table1 where id <= a.id) = @N
      

  3.   

    CREATE PROCEDURE p_GetKeyID
        @N int
        @IDN int OUTPUT
    AS
    --表里须没有字增字段
    select identity(1,1) F0,t.id into #temp from tablename t order by id desc
    select @IDN=id from #temp where F0=@n
    go
      

  4.   

    txlicenhe(马可&不做技术高手)
    你的代码我很难理解,那个table1 和 a 是什么意思?
      

  5.   

    大江东去的代码 好像和westbulls(westbulls)一个意思
      

  6.   

    select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
    select top 1 * from #temptable where iid=NOR:select top 1 * from yourTable where id not in(select top N-1 id from table)
    ID为表具有唯一值的任何字段查询N-M条记录。
    select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
    select top M-N * from #temptable where iid>=NOR:select top M-N * from yourTable where id not in(select top N-1 id from table)
    ID为表具有唯一值的任何字段