似水无痕

http://www.fushunboy.com, http://www.kunet.cn, http://www.gotdotnet.cn
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

asp.net 分面控件存储过程改进

Posted on 2006-03-03 17:12  似水无痕  阅读(309)  评论(0编辑  收藏  举报
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO






ALTER      procedure pt_GetSearchResult  
(    
@TableName    NVarChar(100),--表名
    @UniqueColumeName    NVarChar(100),--表中的ID列名称
    @VcharCondiction NVarChar(100), --查询条件 
    @PageSize int
    
@PageIndex int,
    
@docount bit)  
as  
--定义变量
declare @cTemp NVarChar(200),@indextable NVarChar(100)

--默认将表的唯一列的列名设置成ID
if @UniqueColumeName =''
set @UniqueColumeName = 'ID'

set nocount on  
--得到记录总数
if(@docount=1)  
    
begin
        
set @cTemp = 'select count(*) from '+@tableName + ' '+ @VcharCondiction
        
        
exec (@cTemp)
    
end
else  
--得到结果集
    begin  
        
        
set @indextable = '##temAspPage'
         
--判断定义的临时表是否已经存在
        IF EXISTS(SELECT name FROM tempdb.dbo.sysobjects 
          
WHERE  name = @indextable      AND      type = 'U')
        
begin
          
--如果存在 删除临时表
          set @cTemp =  N' DROP TABLE ' +@indextable
          
exec (@cTemp)
        
end
        
--创建临时表和索引
        set @cTemp =     N' create table '+@indextable+'(id int identity(1,1),nid int)'+
                
' CREATE UNIQUE CLUSTERED INDEX indextable_ind   ON ' +@indextable +'(id)'
        
exec (@cTemp)
        
          
        
declare @PageLowerBound int  
        
declare @PageUpperBound int  
        
set @PageLowerBound=(@pageindex-1)*@pagesize  
        
set @PageUpperBound=@PageLowerBound+@pagesize  
        
set rowcount @PageUpperBound  
        
        
--将符合条件的nid 记录到表里
        set @cTemp = 'insert into  '+@indextable+'(nid) select newsid from wqnews  '+ @VcharCondiction
        
--print @cTemp
        exec (@cTemp)
        
        
--将符合条件的结果集显示出来
        set @cTemp='     select O.newsid,O.heading,O.source,O.author,O.addtime from wqnews O,'+    
                
@indextable +    ' t where O.newsid=t.nid  and t.id> '+    
                
cast(@PageLowerBound as varchar)    +    ' and t.id<= '+
                
cast(@PageUpperBound as varchar)     +    ' order by t.id  '
        
print @cTemp
        
        
exec (@cTemp)
    

    
end  

set nocount off  





GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


dbo.pt_GetSearchResult 'wqnews','newsid','',16,182,0 这么去调用