我想出了这个查询,赞美时不会产生任何错误,但我不知道我是否可以使用这个 select
语句作为value
insert into store(c1 ,artno, c3, c4, c5, c6, c7 )
select '1', a.artno, 0,0.0,null,null,null
from art a
left join store s on s.artno=a.artno
inner join status b on a.artno = b.artno
where b.state ='5'
and s.artno is null
and a.artgroup not in('63','280')
我还看到了另一种可以使用的替代方法,但不确定它是否可以insert
按照我的要求使用,我看到这是在存储过程中实现的,所以只是抓住了它是否可以使用的想法?
declare @artno as varchar(150);
declare @count as tinyint
Declare cS CURSOR For
select a.artno
from art a
left join store s on s.artno=a.artno
inner join status b on a.artno = b.artno
where b.staus ='5'
and s.artno is null
and a.artgroup not in('63','280')
Open cS
Fetch NEXT from cS into @artno
While @@FETCH_STATUS=0
select @count=COUNT(*) from store where artno=@artno
if @count=0
BEGIN
insert into store(c1 ,artno, c3, c4, c5, c6, c7 )
values('1', a.artno, 0,0.0,null,null,null)
fetch next from cS into @artno
END
close cS
deallocate cS
一些解释哪些使用,哪些不使用以及为什么,也会对我的知识有所帮助。