7月 18, 2015

sql用while迴圈

declare @rt nvarchar(4)
declare @rr nvarchar(4)
declare @uu int
set @uu=0
while @uu < 22 --(select count(單位代碼) from View_LiveUnit where 單位代碼 < 0242)
begin
--print @uu
select top 1 @rr=單位代碼 from View_LiveUnit order by 單位代碼 --where 單位代碼 > @rr
select top 1 @rt=單位代碼 from View_LiveUnit where 單位代碼 > @rr order by 單位代碼
print @rt
set @uu+=1
end

沒有留言: