zoukankan      html  css  js  c++  java
  • mssql 创建存储过程简单实例

    CREATE procedure [dbo].[cp_User_Increment]
        @channelId int,
        @currentPage int,
        @pageSize int,
        @userId int
    as
    
    if @channelId<=0
        begin
            select 
            CurrentTime,
            Count
            from
            (
                select 
                *,
                ROW_NUMBER() OVER(ORDER BY CurrentTime DESC) AS RowNum 
                from 
                (
                    select 
                    CONVERT(varchar(12), AddTime, 111 ) as CurrentTime,
                    COUNT(1) as Count 
                    from Users 
                    where IsDel=0 and ChannelId in (select ChannelId from Channel_User where UserId=@userId)
                    group by CONVERT(varchar(12), AddTime, 111) 
                )a 
            )b
            where RowNum BETWEEN (@currentPage-1)*@pageSize+1 and @currentPage*@pageSize
        end
    else
        begin
        
            select 
            CurrentTime,
            Count
            from
            (
                select 
                *,
                ROW_NUMBER() OVER(ORDER BY CurrentTime DESC) AS RowNum 
                from 
                (
                    select 
                    CONVERT(varchar(12), AddTime, 111 ) as CurrentTime,
                    COUNT(1) as Count 
                    from Users
                    where IsDel=0 and ChannelId=@channelId and ChannelId in (select ChannelId from Channel_User where UserId=@userId)
                    group by CONVERT(varchar(12), AddTime, 111) 
                )a 
            )b
            where RowNum BETWEEN (@currentPage-1)*@pageSize+1 and @currentPage*@pageSize
        end
    
    GO
  • 相关阅读:
    分布式事务-第一刀
    Qt
    自描述C++部分面试题集
    读书笔记6.21
    STL vector容器 和deque容器
    C++ STL框架
    C++ 多态
    C++ 虚继承
    C++ 类的继承和派生
    C++ 类中的函数重载
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/5548536.html
Copyright © 2011-2022 走看看