加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver2000的分页,条件过滤

发布时间:2020-12-12 13:00:28 所属栏目:MsSql教程 来源:网络整理
导读:今天写sqlserver2000的分页,条件过滤时查询了一些博客,找了一些常用的分页的解决方案, 主要有三中:1. not in 2. id大于 ?? ?3.存储过程 此处我就列举个自己感觉最简单,最容易理解,最好用的方案。也就是not in? select top 页容量数 * from template wh

今天写sqlserver2000的分页,条件过滤时查询了一些博客,找了一些常用的分页的解决方案,

  主要有三中:1. not in

         2. id大于

??        ?3.存储过程

此处我就列举个自己感觉最简单,最容易理解,最好用的方案。也就是not in?

            select top 页容量数  *   from template where id not in ( 
				select top (页号-1)*页容量 id from template
				 where name like '%'+#{name}+'%'
				 order by id desc
		     ) 
		    and name like '%'+#{name}+'%'

		     order by id desc

  

<select id="retrieveTemplatesByPage" parameterType="map" resultType="map">
        select top ${pageSize} id,name,pic from template where id not in ( select top ${noRow} id from template <where>
                    <if test="name != null and name != '' "> name like '%'+#{name}+'%'
                    </if>
                </where>
                 order by id desc ) <if test="name != null and name != '' ">
            and name like '%'+#{name}+'%'
        </if>
         order by id desc
    </select>

这段代码是在mybatis中写的动态分页语句:

注意点:1.${pageSize},${noRow} ?在sqlserver中 top 关键词后不能用 ?占位符,所以不能写#{} ,智能写${}

    2.过滤条件 ?此处我选择在内层和外层都加上相同的过滤条件,这种感觉比较简单易懂,有点类似oracle的三层分页机制

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读