declare @id int,@u_name varchar(50),@u_pwd varchar(50)
set @id=1
while @id1000
begin
if exists (select u_name from users where u_id=@id)
begin
select @u_name=u_name,@u_pwd=u_pwd from users where u_id=@id --获取源数据
if not exists (select u_name from new_users where u_name=@u_name) -- 判断是否有重复的U-name项
begin
insert into new_users(u_name,u_pwd) values(@u_name,@u_pwd)
end
end
set @id=@id+1
end
select * from new_users