[导入]RowCount 高效分页(续)

   上篇的分页思路很好,不过当数据量大的时候就会很慢,主要原因是插入表变量是浪费了系统资源.如果能取查询的行号,就不需要这个表变量了,sql05为我们提供了一个 Row_Numbe() over( order by col) 功能就可以取行号了。改进如下:

     ALTER procedure [dbo].[EI_CompanyFile_SearchEnterInfo] 
(@skey NVarChar(100), 
@pagesize int, 
@pageindex int, 
@docount bit,
@SearchType nvarchar(1),
@i int out) 
as
set nocount on 
if(@docount=1)
begin
declare @count1 int,@count2 int,@count3 int

if(@SearchType='1')
  begin
 
 select @i=count(1) from
 (
 select id from EnterAAAInfo eai where eai.CreditNumber like '%'+@skey+'%' union
 select id  from EnterInfo ei where ei.CreditNumber like '%'+@skey+'%' union
 s 阅读全文
类别:sql笔记 查看评论
文章来源:http://hi.baidu.com/%B3%C2%C1%A2/blog/item/e078d0002d70d311738b6511.html

posted @ 2006-09-07 17:13  种地的汉子  Views(211)  Comments(0)    收藏  举报