CREATE PROCEDURE upGetCountPPP
@ChannelPath varchar(200),
@StartDate datetime,
@EndDate datetime,
@Flag int
AS
declare @sql nvarchar(4000)
if(@Flag=1)
begin
set @sql = 'declare @aaa int declare @bbb int
SELECT @aaa=sum(a.num) from (SELECT count(distinct postingguid) num,channelpath FROM VUserWorkLogs where PublishDate between '''+convert(char(10),@StartDate,120)+''' and '''+convert(char(10),@EndDate,120)+''' and ChannelPath like ''%'+@ChannelPath+'%'' and actiontype=2 group by channelpath) a
SELECT @bbb=sum(b.num) from (SELECT count(distinct postingguid) num,channelpath FROM VUserWorkLogs where PublishDate < '''+convert(char(10),@StartDate,120)+''' and ChannelPath like ''%'+@ChannelPath+'%'' and actiontype=2 group by channelpath) b
if(@aaa = NULL)
begin
Select @aaa = 0
Select @bbb as 期初,@bbb+@aaa as 期末,@aaa as 新增
end
ELSE if(@bbb = NULL)
begin
Select @bbb = 0
Select @bbb as 期初,@bbb+@aaa as 期末,@aaa as 新增
end
else
Select @bbb as 期初,@bbb+@aaa as 期末,@aaa as 新增
'
end
else
begin
set @sql = 'select top 5 * from VUserWorkLogs'
end
print @sql
exec sp_executesql @sql
GO
===============================================================
CREATE PROCEDURE upGetCountQQQ
@ChannelPath varchar(200),
@StartDate datetime,
@EndDate datetime,
@Flag int
AS
declare @sql nvarchar(4000)
if(@Flag=1)
begin
set @sql = 'declare @aaa int declare @bbb int
SELECT @aaa=sum(a.num) from (SELECT count(distinct postingguid) num,channelpath FROM VUserWorkLogs where PublishDate between '''+convert(char(10),@StartDate,120)+''' and '''+convert(char(10),@EndDate,120)+''' and ChannelPath like ''%'+@ChannelPath+'%'' and actiontype=2 group by channelpath) a
SELECT @bbb=sum(b.num) from (SELECT count(distinct postingguid) num,channelpath FROM VUserWorkLogs where PublishDate < '''+convert(char(10),@StartDate,120)+''' and ChannelPath like ''%'+@ChannelPath+'%'' and actiontype=2 group by channelpath) b
Select ISNULL(@bbb,0) as 期初,ISNULL(@bbb,0)+ISNULL(@aaa,0) as 期末,ISNULL(@aaa,0) as 新增
'
end
else
begin
set @sql = 'select top 5 * from VUserWorkLogs'
end
print @sql
exec sp_executesql @sql
GO