Sql 使用存储过程从临时表插入数据

Sql 使用存储过程从临时表插入数据,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,我想从多个表中插入数据。其中一个表是临时表,其中包含多个数据,即字段名为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

我想从多个表中插入数据。其中一个表是临时表,其中包含多个数据,即字段名为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 
--请检查这个,它可能达到您的要求

    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 
--请检查这个,它可能达到您的要求

    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 

切勿在
FROM
子句中使用逗号。始终使用正确的显式
JOIN
语法。insert子句中的select语句是否返回某些内容?如果是,则是回滚事务;如果不是,则修复事务。切勿在
FROM
子句中使用逗号。始终使用正确的显式
JOIN
语法。insert子句中的select语句是否返回某些内容?如果是,您正在回滚您的事务,如果不是,则修复它。不,它不工作,输出与我的代码相同不,它不工作,输出与我的代码相同