delphi中sql实现while循环插入,不存在则插入

 ' declare @i int; '+
' set @i=0; '+
' while @i<4 '+
' begin '+
' insert into NBCommission(Type,ItemNo,Unit,Amount,CType) '+
' select convert (varchar,@i),a.ItemNo,b.code,''0'',''0'' from InvtItemItem a,Nbunit b where a.unit=b.code and '+
' (not exists (select * from NBCommission where NBCommission.type=convert (varchar,@i) and '+
' NBCommission.ItemNo=a.ItemNo and NBCommission.Unit=b.code)); ' +
' set @i=@i+1; '+
' end ; '

posted @ 2017-09-20 10:41  快乐的正能量  阅读(376)  评论(0编辑  收藏  举报