首页 新闻 会员 周边

请问以下显示的红色Sql语句是什么意思呢

0
悬赏园豆:5 [已解决问题] 解决于 2009-11-22 15:55

ALTER procedure [dbo].[Get_ClassProduct]
(@startIndex int,
@endIndex int,
@Classid int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(*) As Counts from Product where classid=@classid
else
begin
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex

insert into @indextable(nid) select ID from Product  where classid=@classid order by ID desc
select * from Product O,@indextable t where O.ID=t.nid
and t.id between @startIndex and @endIndex order by t.id
end
set nocount off

boboisboy的主页 boboisboy | 菜鸟二级 | 园豆:346
提问于:2009-11-12 10:28
< >
分享
最佳答案
0

定义一个table变量,即表变量,再往表变量中插入一些数据

MSSQL2000开始支持表变量
http://www.cnblogs.com/downmoon/archive/2007/12/29/1019655.html

http://www.cnblogs.com/downmoon/archive/2007/12/29/1019895.html

收获园豆:5
邀月 | 高人七级 |园豆:25475 | 2009-11-12 10:43
其他回答(2)
0

第一段:声明一个表变量,等价于创建一个临时表(函数里面不支持临时表,所以表变量的出现可以很好的解决这个问题,而且在性能上也有其可取的地方。)

第二段:使 SQL Server 在返回指定的行数之后停止处理查询

第三段:插入数据,当记录数达到第二段设定的数值时停止。

综合上述:你的proc存在一定的隐患,你既然指定了开始和结束位置,第二段应该就是取的一个相对差值。

Tim Lee | 园豆:350 (菜鸟二级) | 2009-11-12 10:46
0

往临时表插入数据

Y'冬眠℡ | 园豆:246 (菜鸟二级) | 2009-11-12 15:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册