mssql 创建存储过程简单实例

时间:2023-03-09 19:12:15
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

相关文章