码迷,mamicode.com
首页 > 数据库 > 详细

SQL循环

时间:2016-06-18 15:24:44      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

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循环

标签:

原文地址:http://www.cnblogs.com/ssk-bak/p/5596152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!