I want to insert records into a TempTable. Something like this:
insert into ##tempT
SELECT * FROM MyTable
MyTable contains a large amount of records so the "insert into" takes a long time.
If I try to run:
SELECT COUNT(*) FROM ##tempT
it returns always "0" until all records from "MyTable" are inserted by INSERT INTO command.
How can I get a progress count that advise me how many records are in ##tempT?
I need to update a progress bar value while the SQL command is running.
Thank you.
BULK INSERT statement BULK INSERT loads data from a data file into a table. This functionality is similar to that provided by the in option of the bcp command; however, the data file is read by the SQL Server process. For a description of the BULK INSERT syntax, see BULK INSERT (Transact-SQL).
INSERT-SELECT-UNION query to insert multiple records Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table.
Because the 'INSERT … SELECT' inserts data into an existing table, it is slower and requires more resources due to the higher number of logical reads and greater transaction log usage. However, providing the query hint to lock the entire destination table, the two statements perform exactly the same.
try
set transaction isolation level read uncommitted
SELECT COUNT(*) FROM ##tempT
You can split your query up.
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
You'll notice that you'll need some sort of RecordNumber field to make this work though. There are various ways to accomplish that you can search for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With