如何插入数据库记录?
我有一表a1,字段
id fid name
1 0 abc
2 0 ada
3 0 add
4 1 aaa
5 1 bbb
6 2 ccc
7 2 afdf
8 3 aaa
我现在需要将fid不为0的,将fid不同值分别插入一条记录,如何写?求教?
也就是上述fid 为 1,2,3 分别增加一条记录.
问题点数:20、回复次数:2Top
1 楼huailairen(流浪猫--很想养只猫,带着它到处流浪。)回复于 2006-03-03 23:43:47 得分 12
select distinct fid into temp from a1 where fid<>0
isnert into a1(fid) select fid from temp
drop table tempTop
2 楼mm2love2zz(never stop.)回复于 2006-03-04 00:10:10 得分 8
declare @a int,@b int,@c varchar(10)
select distinct fid into # from a1 where fid <> 0
declare cur cursor for select fid from #
open cur
fetch next from cur into @a
while @@fetch_status = 0
begin
insert a1 select @b,@a,@c
fetch next from cur into @a
end
close cur
deallocate curTop




