zoukankan      html  css  js  c++  java
  • sqlserver通用存储过程

    USE [TnpeemSDB]
    GO
    /****** Object:  StoredProcedure [dbo].[pro_GeneralPaged]    Script Date: 10/26/2015 15:58:50 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- Maticsoft.BLL.list.Lists pro = new Maticsoft.BLL.list.Lists();
     -- 调用方法 DataSet ds = pro.ByPro(PageSize, PageIndex, “查询条件”, ”需要分页的表名”, ”需要分页排序的列名”);
     -- 存储过程方法名固定
    
     
    ALTER procedure [dbo].[pro_GeneralPaged]
       @PageIndex Int,--页码
       @PageSize Int,--每页显示记录
       @StrWhere nvarchar(1000),--Where条件
       @TableName nvarchar(1000), --进行分页的表
       @RowName nvarchar(1000),   --进行分页排序的字段
       @RecordCount Int out,--总记录数
       @PageCount Int out --总页数
       as
       
       declare @SQLSTR nvarchar(4000) --查询语句
       
       IF @RecordCount is null
    	BEGIN
    		DECLARE @sql nvarchar(4000)
    		SET @sql=N'select @RecordCount=count(*)'
    			+N' from '+ @TableName +' where 1=1 '
    			+N' '+@StrWhere
    		EXEC sp_executesql @sql,N'@RecordCount int OUTPUT',@RecordCount output
    	END
    	set @PageCount =ceiling(@RecordCount*1.0/@PageSize)
    	if @PageIndex>@PageCount
    	begin
    		set @PageIndex=@PageCount
    	end
       if @PageIndex<1
    	begin
    		set @PageIndex=1
    	end
    	
    if @PageIndex=1 or @PageCount<=1
    	begin
    		set @SQLSTR='select top '+str(@PageSize)+' * from '+ @TableName +' where 1=1 '+ @StrWhere +' order by '+@RowName+' desc'
    	end 
    	else if @PageIndex=@PageCount
    	begin
    		set @SQLSTR='select * from (select top '+ str(@RecordCount-@PageSize*(@PageIndex-1))+' * from '+ @TableName +' where 1=1 '+ @StrWhere + ' order by '+@RowName+' asc)  TempTable order by '+@RowName+' desc'
    	end
    	else 
    	begin
    		set @SQLSTR='select top '+str(@PageSize)+' * from (select top '+str(@RecordCount-@PageSize*(@PageIndex-1))+' * from '+ @TableName +' where 1=1 '+@StrWhere+'order by '+@RowName+' asc) TempTable order by '+@RowName+' desc'
    	end
    	set @SQLSTR=@SQLSTR +' select rcount = '+str (@RecordCount)+',pcount='+ str(@PageCount)
    	exec (@SQLSTR)
    
  • 相关阅读:
    b/s批量下载文件
    b/s批量下载图片
    python函数总结(转载的 有空看下)
    使用命令行执行需要传参的 py文件的方法
    Jmeter3.1官方自带的HTML图形测试报告 + 汉化 (Jmeter 3.1~5.0通用)(有空试一下)
    Jmeter 获取响应时间图形、TPS的三个插件(有空试一下)
    把表里面的字段连起来 输出到一个字段里面的方法 concat()
    testng要了解的
    包的相互调用的方法
    包目录展示方法设置,和 包里面建包的方法
  • 原文地址:https://www.cnblogs.com/majiabin/p/4911476.html
Copyright © 2011-2022 走看看