CREATE procedure Get_Job
(@startIndex int,
@endIndex int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(*) AS Counts from Job
else
begin
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select ID from Job order by ID desc
select * from Job O,@indextable t where O.ID=t.nid
and t.id between @startIndex and @endIndex order by t.id
end
set nocount off
GO
新手请教存储过程
数据库中有,该过程是获取 JOB 信息,初步看来好像是 数据分页 有关
请教1)@docount bit) 参数说明意思
2)begin - end 间程序的详解
(@startIndex int,
@endIndex int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(*) AS Counts from Job
else
begin
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select ID from Job order by ID desc
select * from Job O,@indextable t where O.ID=t.nid
and t.id between @startIndex and @endIndex order by t.id
end
set nocount off
GO
新手请教存储过程
数据库中有,该过程是获取 JOB 信息,初步看来好像是 数据分页 有关
请教1)@docount bit) 参数说明意思
2)begin - end 间程序的详解
set rowcount @endIndex
insert into @indextable(nid) select ID from Job order by ID desc
select * from Job O,@indextable t where O.ID=t.nid
and t.id between @startIndex and @endIndex order by t.id
2)begin - end 间程序的详解 --声明一个表值变量,插入相关数据,再关联查询.
set rowcount @endIndex --当记录数达到@endIndex时就会停止处理查询 --把JOb表里的数据排序后插入到变量表里
insert into @indextable(nid) select ID from Job order by ID desc --查询数据(变量表里的ID在传进来的开始和结束ID的范围内),并排序
select * from Job O,@indextable t where O.ID=t.nid
and t.id between @startIndex and @endIndex order by t.id
为1的时候做一种操作。
为0的时候做另外一种操作。
SQL codedeclare @indextable table(id int identity(1,1),nid int) --声明本地变量表
set rowcount @endIndex --当记录数达到@endIndex时就会停止处理查询 --把JOb表里的数据排序后插入到变量表里
insert into @indextable(nid) select ID from Job order by ID desc --查询数据(变量表里的ID在传进来的开始和结束ID的范围内),并排序
select * from Job O,@indextable t where O.ID=t.nid
…
[/Quidote ]
int identity(1,1),nid int 这两参数啥意思
这不是参数,这是一个表变量@indextable,这个表含有两个字段id和nid,其中id是自增列,从1开始,每插入一行自动加1
int identity(1,1),nid int 这两参数啥意思这是变量表里的两个字段,ID是自增长列,nid是准备下面的从JOB表里往这里插入值的字段,最后再用这个字段做为条件把数据查询出来。