34,593
社区成员
发帖
与我相关
我的任务
分享
CREATE PROCEDURE pro_statbytype
@sBegin datetime,
@sEnd datetime,
@sType varchar(20)
as
begin
SET NOCOUNT ON;
declare @l int
declare @n int
declare @sql_str varchar(1000)
set @n=1
set @l=datediff(month,@sBegin,@sEnd)+1
set @sql_str=''
while @n <=@l
begin
if @n=1
begin
set @sql_str='select (select count(*) from TABLE_'+replace(convert(varchar(7),dateadd(month,@n,@sBegin),120),'-','')+' where sName='''+@sType+''')'
end
else
begin
set @sql_str='+(select count(*) from TABLE_'+replace(convert(varchar(7),dateadd(month,@n,@sBegin),120),'-','')+' where sName='''+@sType+''')'
end
set @n=n+1
end
--print @sql_str
exec(@sql_str)
end
CREATE PROCEDURE pro_statbytype
@sBegin datetime
@sEnd datetime
@sType varchar(20)
as
begin
SET NOCOUNT ON;
declare @l int
declare @n int
declare @sql_str varchar(1000)
set @n=1
set @ldatediff(month,@sBegin,@sEnd)+1
set @sql_str=''
while @n <=@l
begin
if @n=1
begin
set @sql_str='select (select count(*) from TABLE_'+replace(convert(varchar(7),dateadd(month,@n,@sBegin),120),'-','')+' where sName='''+@sType+''')'
end
else
begin
set @sql_str='+(select count(*) from TABLE_'+replace(convert(varchar(7),dateadd(month,@n,@sBegin),120),'-','')+' where sName='''+@sType+''')'
end
set @n=n+1
end
'print @sql_str
exec(@sql_str)
end