• 【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
  • 相关阅读:
    树上DP
    区间dp
    [持续更新]学习并记忆 Linux 下的常用的命令
    区间dp
    codevs 2152
    树上DP入门题
    差分与前缀和
    POJ
    VJ
    Week 5: Object Oriented Programming 9. Classes and Inheritance Exercise: int set
  • 原文地址:https://www.cnblogs.com/baiyunchen/p/4983750.html
Copyright © 2020-2023  润新知