• 分页存储过程


    ALTER PROCEDURE [dbo].[proc_Hotel_Pagedata] 
        @pageSize int, 
        @pageCurrent int,
        @province varchar(20),
        @city varchar(20),
        @brandId varchar(20)
    AS
    	declare @sql nvarchar(4000)
    BEGIN
    	select * from 
    	(select ROW_NUMBER() over(ORDER BY hotelId) RowNum, * from nbapisdk_Hotel where 
    	province = (CASE WHEN (@province IS NULL) THEN province ELSE @province END) 
    	and city = (CASE WHEN (@city IS NULL) THEN city ELSE @city END) 
    	and brandId = (CASE WHEN (@brandId IS NULL) THEN brandId ELSE @brandId END)
    	)OrderData 
    	where RowNum between (@pageCurrent - 1)*@pageSize + 1 and @pageCurrent * @pageSize order by hotelId
    	execute(@sql)
    END

    上面是正常的SQL语句,下面是拼接的分页存储过程

    ALTER PROCEDURE [dbo].[proc_tourol_B2COrder_Pagedata]
        @pageSize int, 
        @pageIndex int,
        @count int out,
        @sqlwhere nvarchar(200)
        
    AS
    declare @sql nvarchar(4000)
    declare @sql2 nvarchar(4000)
    BEGIN
    	set @sql=
    	'select * from 
    	(select ROW_NUMBER() over(ORDER BY Orderid) RowNum, * from tourol_B2COrder '+@sqlwhere+'
    	)OrderData 
    	where RowNum between '+CONVERT(nvarchar(100),@pageIndex)+'*'+CONVERT(nvarchar(100),@pageSize)
    	+' + 1 and ('+CONVERT(nvarchar(100),@pageIndex)+'+1) * '+CONVERT(nvarchar(100),@pageSize)
    	+' order by Orderid'
    	print @sql
    	exec (@sql)
    	
    	set @sql2=
    	'select @count=count(*) from 
    	(select ROW_NUMBER() over(ORDER BY Orderid) RowNum, * from tourol_B2COrder '+@sqlwhere+'
    	)OrderData'
    	print @sql2
    	exec sp_executesql @sql2,N'@count INT OUT',@count=@count OUT
    	print @count
    END

    这里需要注意的是传出参数的写法

  • 相关阅读:
    代码写界面的工厂类
    Masonry的一些等间距布局
    开发中的小细节随记
    ios7 实现应用内保真截屏
    利用GCD实现单利模式的宏代码
    AVAudioPlayer的锁屏播放控制和锁屏播放信息显示
    NSXMLParser自定义的一个xml解析工具
    利用NSURLSession完成的断点续传功能
    AVFoundation下的视频分帧处理
    Redis自学笔记:4.2进阶-过期时间
  • 原文地址:https://www.cnblogs.com/TivonStone/p/2985175.html
Copyright © 2020-2023  润新知