Solved
Using a TSQL cursor to import data
Posted on 2011-03-08
I have written an export routine in TSQL which imports data from a flat file database into a new database which contains different tables but links all the fields to the main data table.
Having been able to successfully import one data record and all of its linked fields (USING SELECT AND INSERT INTO statements, I need to automate the process using a cursor and import thousands of records. I would like to achieve the following:
Import from a select statement all of the main table data, which I believe would be loaded into the cursor. This holds the foreign key for linking the other tables
I then want to pass the record IDs from the above results and somehow link this with the next batch of inserts in the cursor so that all of the data is linked to the correct tables when running the cursor?
How would I go about this in TSQL?