A:select * from materials where Fbatchman=1 and fclsid in (1,3) and fitemid not in (select fitemid from icbatchnorule)
B: insert into ICBatchNoRule(FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail) Values(1,28734,8,0,'','',6,'x','',1)
------解决方案-------------------- lz:基于你的问题的解答:
1。你可以这样保存结果到你的目的表中: insert into ICBatchNoRule(FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail) Values(1,28734,8,0,'','',6,'x','',1) select * from materials where Fbatchman=1 and fclsid in (1,3) and fitemid not in (select fitemid from icbatchnorule)
create proc ProcName[(ParmName ParmType)]
as
begin
insert into ICBatchNoRule(FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail)
SELECT FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail
from
materials where Fbatchman=1 and fclsid in (1,3) and fitemid not in (select fitemid from icbatchnorule)
end
------解决方案-------------------- icbatchnorule表已经存在: INSERT INTO icbatchnorule select FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail from materials where Fbatchman=1 and fclsid in (1,3) and fitemid not in (select fitemid from icbatchnorule) icbatchnorule表不存在: select FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail INTO icbatchnorule from materials where Fbatchman=1 and fclsid in (1,3) and fitemid not in (select fitemid from icbatchnorule)
------解决方案--------------------
SQL code
/*
用 “insert into tablename(col1, col2)
select col1='1111', col2='222' from othertable”模式
*/
insert into ICBatchNoRule(FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail)
select FID,Fitemid, ............ --这里写入对应上一行对应位置的字段
from materials
where Fbatchman=1 and fclsid in (1,3) and fitemid not in (select fitemid from icbatchnorule)
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
--递增序列
declare @idd int,
--获取当前最大序列号 select @idd=max(FPropertyid) from FPropertyid
--逐条执行 insert into ICBatchNoRule(FID,Fitemid,FPropertyid,Fuseshortnumber,FFormatDate,FSelDefine,FWidth,Fcharacter,FSubcharacter,FDetail) SELECT FID, @idd+1,......