INSERT INTO SELECT - a large number of records

I want to insert records into TempTable. Something like that:

insert into ##tempT
SELECT * FROM MyTable 

MyTable contains a large number of entries, so "insert into" takes a lot of time.

If I try to run:

SELECT COUNT(*) FROM ##tempT

it always returns “0” until all records from “MyTable” have been inserted with the INSERT INTO command.

How can I get a progress count that tells me how many records are in ## tempT?

I need to update the progress bar value while executing an SQL command.

Thank.

+5
source share
3 answers

try

set transaction isolation level read uncommitted
SELECT COUNT(*) FROM ##tempT
+8
source

You can split the request.

x = number of records in MyTable / 100
i = 0

do until we're done
    queryString = "insert into ##tempT "
    queryString += "select top " + x " + " * FROM MyTable "
    queryString += "where RecordNumber > " + i

    Execute queryString
    Update Progress Bar
    i = i + x
loop

, - RecordNumber, . , .

+1

Use the stored procedure and the DECLARE variable COUNT and treat it as a loop variable and each time the insert is done, increment COUNT by 1 and continue to print using another query when you want to know the .Or count, return this count the procedure and read it in your program to update the progress bar. :)

+1
source

All Articles