setansi_nulls
onset
quoted_identifier
ongo
--[selectbase] 1,1,'( select j.*,u.p_name from job j left join users u on j.userid=u.id) t','flag=0'
alter
procedure
[selectbase
]@pageindex
int,
@pagesize
int,
@tablename
nvarchar
(2000
), @where
nvarchar
(2000)=
''as
declare
@rowcount
intdeclare
@intstart
intdeclare
@intend
intdeclare
@column1
varchar(32
) --
第一列名稱
declare
@sql
nvarchar
(2000
), @wherer
nvarchar
(1000
), @orderby
nvarchar
(1000
) set
@rowcount=0
setnocount
onif
@where
<>
''begin
set@where='
and '+
@where
endif
charindex('
order by',
@where
)>
0begin
set@wherer
=substring
(@where, 1
, charindex('
order by',
@where)-
1)
--取得條件
set@orderby
=substring
(@where
, charindex('
order by',
@where
), len
(@where
))
--取得排序方式(order by 字段 方式)
endelse
begin
set@wherer
=@where
set@orderby='
order by id asc
'end
set@sql='
select @rowcount=count(*) from '+
cast
(@tablename
asnvarchar
(2000))+
'where 1=1 '+
@wherer
exec
sp_executesql
@sql,n'
@rowcount int output',
@rowcount
output
if@pageindex=0
and@pagesize=0
--不進行分頁,查詢所有資料列表
begin
set@sql='
select * from '+
cast
(@tablename
asnvarchar
(2000))+
'where 1=1 '+
@where
endelse
--進行分頁查詢資料列表
begin
set@intstart=(
@pageindex-1
)*@pagesize+1
; set
@intend
=@intstart
+@pagesize-1
declare
@pkname
nvarchar(50
)if(len
(@tablename
)>50)
begin
set@column1='
id'endelse
begin
set@column1
=col_name
(object_id
(@tablename),1
) --
設定第一列名稱
endset
@sql='
create table #tem(row int identity(1,1) not null,joinrow int)
'set
@sql
=@sql+'
insert #tem(joinrow) select '+
@column1+'
from '+
@tablename+'
where 1=1 '+
@wherer
set@sql
=@sql+'
select * from '+
@tablename+'
right join #tem on '+
@column1+'
=#tem.joinrow
'set
@sql
=@sql+'
where #tem.row between '+
cast
(@intstart
asvarchar)+
'and '+
cast
(@intend
asvarchar
) end
--print @sql
exec
sp_executesql
@sql
return
@rowcount
setnocount
off
sql2000下 分頁儲存過程
set quoted identifier off goset ansi nulls on go 名稱 分頁儲存過程 使用示例 exec sp pageindex from stusources 2,10 注意 目前還沒有對輸入的引數進行嚴格的驗證 預設為輸入都是合法有效的 alter proc s...
SQL2000和SQL2005分頁儲存過程
mssql 2000 set ansi nulls on set quoted identifier on goalter procedure dbo proc page2000 tabname nvarchar 100 表名 檢視名 查詢語句 pagesize int 10,每頁的大小 行數 pa...
sql2000儲存過程
自 http www.cnblogs.com a13971240 archive 2008 10 22 1316747.html create proc getdataset tablelist varchar 200 搜尋表的字段,比如 id,datatime,job 用逗號隔開 tablenam...