• 【SQLSERVER学习笔记】分页存储过程+调用


     1 USE [数据库名]
     2 GO
     3 
     4 SET ANSI_NULLS ON
     5 GO
     6 
     7 SET QUOTED_IDENTIFIER ON
     8 GO
     9 CREATE PROCEDURE [dbo].[存储过程名]
    10     @pageIndex INT,
    11     @pageSize INT,    
    12     @totalCount INT OUTPUT    
    13 AS 
    14 SET NOCOUNT ON
    15 
    16 DECLARE @PageStart INT
    17 DECLARE @PageEnd   INT
    18 
    19 SET @pageStart=(@pageIndex-1)*@pageSize
    20 SET @pageEnd=@pageIndex*@pageSize
    21 BEGIN 
    22     SELECT @totalCount=COUNT(1) FROM [dbo].[表名]
    23     SELECT 
    24          [Id]
    25         ,字段1
    26         ,字段2
    27         ,.....        
    28     FROM 
    29         (SELECT 
    30             ROW_NUMBER() OVER (ORDER BY 字段名) AS RowNumber,
    31              [Id]
    32             ,[Name]
    33             ,[Phone]
    34             ,[Age]
    35             ,[CreateTime] 
    36         FROM [dbo].[表名] WITH(NOLOCK)) AS Temp
    37     WHERE Temp.RowNumber>@PageStart AND Temp.RowNumber<@PageEnd
    38     ORDER BY Temp.CreateTime DESC,Temp.Name
    39 END
    40 
    41 GO

    调用此存储过程的方法:

    1 USE [数据库名]
    2 GO
    3 DECLARE @totalResult INT
    4 EXEC [存储过程名] 1,10,@totalResult output
    5 SELECT @totalResult
  • 相关阅读:
    eclipse无法启动问题记录
    java环境配置
    Tomcat配置,Myeclipse破解和各种设置
    Android_Service详解及实例
    WTF
    jQuery实现图片轮播
    jQuery实现皮肤自定义
    CSS中的transform与transition
    checkbox实现全选/全不选
    ng-if可见
  • 原文地址:https://www.cnblogs.com/baiyunchen/p/4983750.html
Copyright © 2020-2023  润新知