sql while 遍历表

declare @n int
declare @rowcount int 
declare @name varchar(50)
create table #temp
(
 id int identity(1,1),
 employeeName nvarchar(100)
)
insert into #temp select name from employee
set @rowcount=@@rowcount
set @n=1
while @n<@rowcount
begin
  select @name=employeename from #temp where id=@n
  print(@name)
  set @n=@n+1
end
drop table #temp

 

你可能感兴趣的:(sql while 遍历表)