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
@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
(@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
Select @IDN = id from table1 a where (select count(*) from table1 where id <= a.id) = @N
@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
你的代码我很难理解,那个table1 和 a 是什么意思?
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为表具有唯一值的任何字段