当前位置:Gxlcms > 数据库问题 > SQL循环

SQL循环

时间:2021-07-01 10:21:17 帮助过:2人阅读

declare @temp Table
(
nf varchar(50),
yf varchar(50),
sm varchar(50)
)
declare @nd varchar(50), @yd int,@i int
set @nd = ‘2016‘
if(@nd = year(getdate()))
begin
set @yd = MONTH(getdate())
end
else
begin
set @yd = 12
end
set @i = 1
WHILE @i <= @yd
BEGIN
insert into @temp
select @nd as nd, @i as yd, count(*) as sm from t_prtc_htbadj
where year(CreateDate)=@nd and month(CreateDate)=@i
set @i = @i + 1
END
select * from @temp

SQL循环

标签:

人气教程排行