您的位置:首页 > 数据库

mssql 创建存储过程简单实例

2016-06-01 09:36 316 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: