怎么用SQL循环插入数据

来源:百度知道 编辑:UC知道 时间:2024/07/04 13:30:02
select nchar(22899)as emp into table1
declare @a int
set @a=22899
while @a<=22910
begin
insert table1 select nchar(convert(char,@a,1))
@a=@a+1
end
select *from table1
drop table table1
高手帮分析下上面的语句错在那儿,怎么才能实现循环插入的效果?
中间有错误,执行次数倒不是重点.

set @a=22899
while @a<=22910

你这样写岂不是只执行2次!

---
insert table1 select nchar(convert(char,@a,1))
改为
insert table1 (字段) select convert( nchar(1),@a)
--[sqlserver 中的convert]

-- 在插入全部字段的情况下,"(字段)"就可以省略.