Reputation: 482
When I am doing condition and in that I am inserting data in a table at that time it showing error i.e. "The multi-part identifier could not be found" in sqlserver
Here is my query
SELECT CASE
WHEN p.id = tmp.ProductId and p.Deleted = 0 and p.Published = 1 and p.VisibleIndividually = 1
THEN
Insert into mysql_abc_Product(ProductId, abcStatus, IsDeleted, InTime, StoreId,LanguageId)
select DISTINCT tmp.ProductId,1,0,GETDATE(),s.Id,l.Id from Language l, Store s, #temp tmp, Product p left join Incremental_Solr_Product isp on isp.ProductId = p.Id
where isp.Id is NULL and p.Deleted = 'False' or p.Published = 'True' or VisibleIndividually = 'True'
ELSE
Insert into mysql_abc_Product(ProductId, abcStatus, IsDeleted, InTime, StoreId,LanguageId)
select DISTINCT tmp.ProductId,1,0,GETDATE(),s.Id,l.Id from Language l, Store s, #temp tmp, Product p left join Incremental_Solr_Product isp on isp.ProductId = p.Id
where isp.Id is NULL and p.Deleted = 'True' or p.Published = 'False' or VisibleIndividually = 'False'
END as Saleable, *
FROM Language l, Store s, Product p left outer join #temp tmp on tmp.productid = p.Id where isp.Id is NULL
Upvotes: 1
Views: 388
Reputation: 2423
You should put the proper joins into this, but here is your solution to the above query. You did not include the table "Incremental_Solr_Product" qualified with "isp" into your last line From statement.
SELECT CASE
WHEN p.id = tmp.ProductId and p.Deleted = 0 and p.Published = 1 and p.VisibleIndividually = 1
THEN
Insert into Incremental_Solr_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId,LanguageId)
select DISTINCT tmp.ProductId,1,0,GETDATE(),s.Id,l.Id from Language l, Store s, #temp tmp, Product p left join Incremental_Solr_Product isp on isp.ProductId = p.Id
where isp.Id is NULL and p.Deleted = 'False' or p.Published = 'True' or VisibleIndividually = 'True'
ELSE
Insert into Incremental_Solr_Product(ProductId, SolrStatus, IsDeleted, InTime, StoreId,LanguageId)
select DISTINCT tmp.ProductId,1,0,GETDATE(),s.Id,l.Id from Language l, Store s, #temp tmp, Product p left join Incremental_Solr_Product isp on isp.ProductId = p.Id
where isp.Id is NULL and p.Deleted = 'True' or p.Published = 'False' or VisibleIndividually = 'False'
END as Saleable, *
FROM Language l, Store s, Product p left outer join #temp tmp on tmp.productid = p.Id
left join Incremental_Solr_Product isp on isp.ProductId = p.Id
where isp.Id is NULL
Upvotes: 1