簡體   English   中英

使用存儲過程從臨時表插入數據

[英]Insert data from temp table using stored procedure

我想從多個表中插入數據。 從表中的一個是臨時表,其中它來自多個數據,即46和47,其字段名稱是productid。 但它不是通過多個條件插入另一個表。

這是我的查詢:

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 

- 請檢查一下它可能達到您的要求。

    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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM