1
複数のテーブルからデータを挿入したい。そのテーブルからは、複数のデータ、すなわちフィールド名がproductidである46と47となる一時テーブルがある。しかし、それは複数の条件で別のテーブルに挿入されていません。ストアドプロシージャを使用してテンポラリテーブルからデータを挿入する
Insert into #temp
select Product.Id
from Product
left outer join In_abc_Product ON In_abc_Product.ID = Product.ID
where In_abc_Product.ID IS NULL
BEGIN
select * from #temp
--Insert data into In_abc_Product where condition is p.Deleted = 'False' or p.Published = 'True' or VisibleIndividually = 'True'
Insert into In_abc_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId,LanguageId)
select tmp.productid,1,0,GETDATE(),s.Id,l.Id from Language l, Store s, #temp tmp left join Incremental_Solr_Product isp on isp.ProductId = tmp.productid
left join product p on p.id = isp.ProductId where isp.Id is NULL and p.Deleted = 'False' or p.Published = 'True' or VisibleIndividually = 'True'
--Insert data into In_abc_Product where condition is p.Deleted = 'True' or p.Published = 'False' or VisibleIndividually = 'False'
Insert into Incremental_Solr_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId,LanguageId)
select tmp.productid,1,0,GETDATE(),s.Id,l.Id from Language l, Store s, #temp tmp left join Incremental_Solr_Product isp on isp.ProductId = tmp.productid
left join product p on p.id = isp.ProductId where isp.Id is NULL and p.Deleted = 'True' or p.Published = 'False' or VisibleIndividually = 'False'
END
END
*決して* FROM句にカンマを使用しないでください。 *常に*適切で明示的な 'JOIN'構文を使用します。 –
insert句のselect文は何かを返しますか?はいの場合は、トランザクションをロールバックしていない場合はそれを修正します。 –