2016-10-18 9 views
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 
+4

*決して* FROM句にカンマを使用しないでください。 *常に*適切で明示的な 'JOIN'構文を使用します。 –

+0

insert句のselect文は何かを返しますか?はいの場合は、トランザクションをロールバックしていない場合はそれを修正します。 –

答えて

0

--Pleaseが、それはあなたの条件件まで達する可能性があり、これをチェックアウト:

は、ここに私のクエリです。

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 into In_abc_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId,LanguageId) 
     select tmp.productid,1,0,GETDATE(),(SELECT S.Id FROM Store s),(SELECT l.Id Language l) 
     from #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 into Incremental_Solr_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId,LanguageId) 
     select tmp.productid,1,0,GETDATE(),(select s.Id from Store s),(select l.Id from Language l) 
     from #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 
+0

nopそれは私のコードと同じ出力が来て動作していません – karan

関連する問題