zoukankan      html  css  js  c++  java
  • SQL Page

    -------------------分页2---------

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[Deer_Page]
    (
    @startIndex INT
    ,@pageSize INT
    ,@strSql varchar(5000) ---查询条件
    ,@TableName varchar(50)
    ,@DoCount AS bit=1 -- 0值返回记录总数, 非 0 值则返回记录
    )
    AS
    begin tran
    IF @DoCount=0
    Goto GetCount
    Else
    Goto GetSearch

    GetCount: --返回记录总数
    DECLARE @SearchSql AS Nvarchar(4000)
    SET @SearchSql= 'SELECT Count(*) AS Total FROM '+@TableName+' WHERE IntReserve1=0'
    exec sp_executesql @SearchSql
    --print @SearchSql
    COMMIT TRAN
    return

    GetSearch: --返回记录
    DECLARE @SqlQuery varchar(4000)
    SET @SqlQuery='SELECT * FROM
    (SELECT ROW_NUMBER() OVER (ORDER BY O.ID ) Row, * from '+@TableName+' O Where IntReserve1=0) as temp
    WHERE Row BETWEEN '+cast(@startIndex as varchar) +' and '+cast(@startIndex+@pageSize-1 as varchar)+ @strsql
    ---print @SqlQuery
    execute(@SqlQuery)
    COMMIT TRAN

  • 相关阅读:
    [leetcode]66Plus One
    [leetcode]64Minimum Path Sum 动态规划
    [leetcode]62.UniquePaths
    [leetcode]54. Spiral Matrix2生成螺旋数组
    Keywords Search HDU
    Division HDU
    Naming Babies UVA
    Pearls POJ
    K-Anonymous Sequence POJ
    Post Office POJ
  • 原文地址:https://www.cnblogs.com/opts/p/7026658.html
Copyright © 2011-2022 走看看