**自:http://www.cnblogs.com/a13971240/archive/2008/10/22/1316747.html
create proc getdataset
@tablelist varchar(200)='*',--搜尋表的字段,比如:』id,datatime,job『,用逗號隔開
@tablename varchar(30), --搜尋的表名
@selectwhere varchar(500)='',--搜尋條件,這裡不用寫where,比如:job=』teacher『and class='2'
@selectorderid varchar(20),--表主鍵欄位名。比如:id
@selectorder varchar(200)='', --排序,可以使用多欄位排序但主鍵字段必需在最前面.也可以不寫,比如:order by class asc
@intpageno int=1, --頁號
@intpagesize int=10 ,--每頁顯示數
@recordcount int output --總記錄數(儲存過程輸出引數)
as
declare @tmpselect nvarchar(600)
declare @tmp nvarchar(600)
set nocount on--關閉計數
set @tmpselect = 'select @recordcount = count(*) from '+@tablename+'
'+@selectwhere
execute sp_executesql
@tmpselect, --執行上面的sql語句
n'@recordcount
int output' , --執行輸出資料的sql語句,output出總記錄數
@recordcount output
if (@recordcount = 0) --如果沒有貼子,則返回零
return 0
/*判斷頁數是否正確*/
if (@intpageno - 1) * @intpagesize > @recordcount --頁號大於總頁數,返回錯誤
return (-1)
set nocount off--開啟計數
if @selectwhere != ''
begin
set @tmpselect = 'select top '+str(@intpagesize)+' '+@tablelist+'
from '+@tablename+'
where '+@selectorderid+'
not in(select top '+str((@intpageno-1)*@intpagesize)+' '+@selectorderid+'
from '+@tablename+'
'+@selectwhere
+' '+@selectorder+'
) and '+@selectwhere
+' '+@selectorder
endelse
begin
set @tmpselect = 'select top '+str(@intpagesize)+' '+@tablelist+'
from '+@tablename+'
where '+@selectorderid+'
not in(select top '+str((@intpageno-1)*@intpagesize)+' '+@selectorderid+'
from '+@tablename+'
'+@selectorder+'
) '+@selectorder
endexecute sp_executesql @tmpselect
return(@@rowcount)
go
sql2000儲存過程
create proc getdataset tablelist varchar 200 搜尋表的字段,比如 id,datatime,job 用逗號隔開 tablename varchar 30 搜尋的表名 selectwhere varchar 500 搜尋條件,這裡不用寫where,比如 job...
SQL 2000解密儲存過程
begin set origsptext1 select ctext from temp where colid n set objectname1 objectname t set origsptext3 select ctext from syscomments where id object ...
sql2000下 分頁儲存過程
set quoted identifier off goset ansi nulls on go 名稱 分頁儲存過程 使用示例 exec sp pageindex from stusources 2,10 注意 目前還沒有對輸入的引數進行嚴格的驗證 預設為輸入都是合法有效的 alter proc s...