if exists (select * from dbo.sysobjects where id = object_id(n'#temp') and objectproperty(id, n'isusertable') = 1)
drop table #temp
create table #temp
(pager2011_id int identity(1, 1) primary key , --索引,分頁時根據這個欄位來取記錄
tableid varchar(20)
)insert into #temp(tableid)
select
nationno
from
tbl_dict_pub_nation
select * from tbl_dict_pub_nation;
select t.*,b.* from dbo.tbl_dict_pub_nation t inner join #temp b on t.nationno=b.tableid
下面乙個是別人寫的
/****** 物件: storedprocedure [dbo].[npc_get] 指令碼日期: 05/20/2008 09:46:18 ******/
create procedure [dbo].[npc_get]
(@pageindex int,
@pagesize int,
@orderby int)as
if @pagesize = 0
select * from npc
else if @pagesize > 0
begin
declare @pagelowerbound int,
@pageupperbound int,
@pagecount int,
@npccount int
--臨時索引表--
create table #pageindex
(indexid int identity(1,1) not null,
npcid int
)if @orderby = 1
begin
insert into #pageindex(npcid)
select
npcid
from
npcorder by
[level] desc
endelse if @orderby = 2
begin
insert into #pageindex(npcid)
select
npcid
from
npcorder by
npctypeid desc
endelse if @orderby = 3
begin
insert into #pageindex(npcid)
select
npcid
from
npcorder by
areaid desc
end--最大頁碼計算--
set @npccount = @@rowcount
set @pagecount = (@npccount - 1) / @pagesize + 1
--頁碼範圍校驗--
if @pageindex < 1 set @pageindex = 1
if @pageindex >=@pagecount set @pageindex = @pagecount
set @pagelowerbound = @pagesize * (@pageindex - 1)
set @pageupperbound = @pagelowerbound + @pagesize + 1
--返回記錄--
select
ts.*,
nt.npctypename,
nl.npclevelname,
nc.npcclassname,
a.areaname,
c.campname
from
npc ts
left join npctype nt on ts.npctypeid = nt.npctypeid
left join npclevel nl on ts.npclevelid = nl.npclevelid
left join npcclass nc on ts.npcclassid = nc.npcclassid
left join area a on ts.areaid = a.areaid
left join camp c on ts.campid = c.campid,
#pageindex tpi
where
ts.npcid = tpi.npcid and
tpi.indexid > @pagelowerbound and
tpi.indexid < @pageupperbound
order by
indexid
select @npccount as npccount,@pagecount as pagecount,@@rowcount as returncount
end
SQL 2000如何分頁
網上搜的sql 2000如何分頁,程式中採用的是方案二的方法,如下 應乙個朋友的要求,貼上收藏的sql常用分頁的辦法 表中主鍵必須為標識列,id int identity 1,1 1.分頁方案一 利用not in和select top分頁 語句形式 select top 頁記錄數量 from 表名 ...
sql2000下 分頁儲存過程
set quoted identifier off goset ansi nulls on go 名稱 分頁儲存過程 使用示例 exec sp pageindex from stusources 2,10 注意 目前還沒有對輸入的引數進行嚴格的驗證 預設為輸入都是合法有效的 alter proc s...
SQL2000表分組問題
現sql2000伺服器上有一張表,格式如下 檔案內容 檔案組 1 a2 a 3 a4 b 5 c6 d 7 e8 e 9 f要實現將表內容更新為 檔案內容 檔案組 a1 a 2 a3 a b4 b c5 c d6 d e7 e 8 ef 9 f意思是將分組資訊直接加在檔案內容之中?如果不用游標,不知...