我用下面的过程怎么只插入了一行数据,print @i也没有打印出来.
--创建存储过程
create proc aa
@degreeID as int,
@sourceDBName as char(20),
@targetDBName as char(20)
as 
begin
declare @i int,
@count int,
@sql varchar(400)
--插入默认角色至目标库
exec('update  '+@targetDBName+'..ParameterTable set ParameterValue=N'''+@degreeID+''' where ParameterName=''DefaultDegreeID''')

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[temp1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[temp1]
--插入临时表
exec('select * into temp1 from '+@sourceDBName+'..UserInfoTable where userType=4')


alter table temp1 add nid int IDENTITY(1,1) select * from temp1 --select @count=max(nid) from temp1 set @count=10 --导出用户(非系统默认的用户)
set @i=1
while @i<=@count
        begin
set @sql='insert into '+@targetDBName+'..UserInfoTable 
select userid,usertype,username,password,sex,birthday,createdate,
cardid,companyid,education,trade,province,city,address,phone,email,
postcode,personalResume,HomePage,networkstatus,linkstatus,deleteflag 
from temp1 where nid='+rtrim(@i)
print @sql
exec(@sql)
set @i=@i+1
print @i
end

drop table temp1

endgo--调用proc
exec aa 4,chinaschool_rs40,chinaschool_rs50_000--删除存储过程
go
drop proc aa