zoukankan      html  css  js  c++  java
  • 获取列表存储过程

    获取列表存储过程如下:

    ALTER PROCEDURE [dbo].[ds_TopListWeek]
        @keyword varchar(30),   -- 区分活动
        @userName varchar(50),  -- 作者
        @title varchar(100),    -- 标题 
        @time varchar(10),      -- 时间
        @pageindex int,         -- 当前页码
        @pagesize int           -- 每页记录数
    AS
    BEGIN
        declare @frmindex int,@endindex int
        set @frmindex=(@pageindex-1)*@pagesize
        set @endindex=@pageindex*@pagesize
    
        declare @sql varchar(3000),@condition varchar(1000),@tempdate datetime,@likeUserName varchar(50),@likeTitle varchar(100)
        --查询时间的周的周一时间
        set @tempdate = dateadd(day,1 - (datepart(weekday,@time) + @@datefirst - 2) % 7 - 1,@time)
        set @condition=' where t.keyword=''' + @keyword + ''' and t.top_type=0'
    
        if (@userName!='' and @userName is not null)
        begin
            set @likeUserName = dbo.f_Filter_EscapeStr(@userName)
            set @condition=@condition+' and t.nickname like ''%'+@likeUserName+'%'' escape ''/'''
        end
        if (@title!='' and @title is not null)
        begin
            set @likeTitle = dbo.f_Filter_EscapeStr(@title)
            set @condition=@condition+' and n.title like ''%'+@likeTitle+'%'' escape ''/'''
        end
    
        set @sql = 'with tb as('
                +'select t.t_id,t.news_id,t.username,t.nickname,t.praisecnt,t.randomcnt,t.praisecnt+t.randomcnt as cnt,t.create_time,t.IsPub,n.title,n.url'
                +' from ds_toplist t inner join sy_news n on t.news_id=n.news_id'
                + @condition
                +' and t.create_time between ''' + convert(varchar(20), @tempdate, 120) +''' and dateadd(day,6,'''+ convert(varchar(20), @tempdate, 23) + ''')'
                +'),tbNoRepeat as ('
                +'select t.* from (select distinct nickname from tb) t1'
                +' cross apply(select top 1 * from tb t2 where t1.nickname=t2.nickname order by t2.cnt desc) t'
                +'),tbRes as('
                +'select t.t_id,t.news_id,t.username,t.nickname,t.praisecnt,t.randomcnt,t.title,'
                +'t.url,t.IsPub,t.create_time,row_number() over(order by (t.praisecnt + t.randomcnt) desc) as place from tbNoRepeat t)'
                +'select *,(select count(1) from tbRes) as pagecount from tbRes'
                +' where place > ' + cast(@frmindex as varchar) +' and place <='+ cast(@endindex as varchar)
        print @sql
        exec (@sql)
    END
  • 相关阅读:
    dedecms图片列表效果调用
    ThinkPHP 中M方法和D方法的具体区别
    在线更新dede程序后 网站出现错误 DedeCMS Error:Tag disabled:"php" more...!
    Form元素示例
    PHP使用frameset制作后台界面时,怎样实现通过操作左边框架,使右边框架中的页面跳转?
    删除UTF-8 BOM头的GUI小工具
    解决 ultraedit 菜单字体模糊
    git使用及一些配置、问题
    shell之基本语法
    shell之iptables
  • 原文地址:https://www.cnblogs.com/wxh19860528/p/3412636.html
Copyright © 2011-2022 走看看