Kumar AU

Kumar AU

  • 1.1k
  • 309
  • 61.9k

Query Performance issue with While Loop

Jun 10 2021 3:00 AM

Dear Team,

Could you please suggest me why the below query takes more time to run and How do I improve the performance on the same.

WHILE EXISTS(
SELECT Top 1 1 FROM #tempPolicyData)
BEGIN
DECLARE @AccountNumber NVARCHAR(50)
SELECT TOP 1 @AccountNumber =AccountNumber FROM #tempPolicyData 
IF Exists( Select Top 1 1 FROM [dbo].[CheckRecords] 
where DetailRecord like '% ' + @AccountNumber +' %')
BEGIN
SELECT * FROM #tempPolicyData INTO  #tempImpactedPolicyData 
where AccountNumber = @AccountNumberENDDelete 
FROM #tempPolicyData where AccountNumber = @AccountNumberEND

 


Answers (1)