2016-10-18 3 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

관련 문제