Hi @ahmed salah ,
In may not be used here. I tested the method to solve the performance problems caused by or. Union all is suitable for NULL:
select * from a
select * from a
where name ='Jane' or name is null
select * from a
where name in('Jane',null)
select * from a
where case when name ='Jane' then name else NULL end=name
select * from a where name='Jane'
union all
select * from a where name is null
For the delete statement, it can be divided into two queries,please check if it works:
DELETE f
FROM Parts.ChemicalProfiles f
INNER JOIN #TempPC t
ON t.ChemicalID = f.ChemicalID
WHERE t.[status]='Not Found in Chemical Master'
DELETE f
FROM Parts.ChemicalProfiles f
INNER JOIN #TempPC t
ON t.ChemicalID = f.ChemicalID
WHERE t.[status] IS NULL
But if there is only the empty string'NULL' in your data, there is no NULL, then you can refer to:
DELETE f
FROM Parts.ChemicalProfiles f
INNER JOIN #TempPC t
ON t.ChemicalID = f.ChemicalID
WHERE case when t.[status]='Not Found in Chemical Master' then t.[status] else 'NULL' end=t.[status]
Or:
DELETE f
FROM Parts.ChemicalProfiles f
INNER JOIN #TempPC t
ON t.ChemicalID = f.ChemicalID
WHERE t.[status] in('Not Found in Chemical Master','NULL')
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.