Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

How to replace while loop with another thing best practice ?

$
0
0

I work on SQL server 2012

I have temp table get data from excel and based on data exist on excel i insert on table inside loop

temp table always have big amount of data may be at least 5000 or 10000 or 15000 or more

I need every iteration increased by 5000 rows insert from temp table

so that i need best solutions for that according to speed and memory like that

and if there are any thing not correct as logic please tell me

my Query as below :

SQL
DECLARE@MaxValueint=(selectMax(DocumentPartID)from#Temp)DECLARE@Currentindexint=0DECLARE@Rows[dbo].[Type_ValidationInPut];while@Currentindex<@MaxValuebeginDELETE@RowsINSERTINTO@Rows(RowNumber,GivenPartNumber,GivenManufacturer)selectTOP5000DocumentPartID,isnull(AffectedProduct,''),isnull(CompanyName,'')FROM#Tempwhere(CategoryID=517884orCategoryID=...<

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>