Cache Sql Record set copy to a table
Hello all,
I have a Recordset object which contains data from a table "XYZ".
Currently i use this object to extract data using %Get(COL1,COL2...) in a loop and than pass it to a function which inserts the data into another dynamically created Table "ABC" for each record. This takes a lot of time when 100's of records.
Is there a way i can directly copy a RecordSet to a dynamic table without looping through..?
Something like copy Recordset (COL1,COL2..)--> "ABC"
Thanks,
Jimmy
There is another way directly with SQL
First, you CREATE a temporary table according to your needs (or have it ready)
Next, you fill it by INSERT directly from SELECT
SELECT COL1,COL2, ... FROM Source.Table WHERE ......
The select is the same as before.
Thank you Robert. But looks like i am running into another issue where data is lost and i am unable to create table.
I really would prefer to find out if there is a way to copy directly a RecordSet to a table or any other faster method rather than looping through the entire Recordset.
You shouldn't be so much concerned on looping the RecordSet
INSERT ...... SELECT ....
looks smaller and smarter but does basically the same
Yep. Select INTO works great if the source and target tables are in same NAMESPACE. I need to copy the data across namespaces, for which i have already some another method.
But i found that copying recordset would also work, since once the object is created i can easily write to another table on a different "NAMESPACE". Only issue is to write to a target table from a recordset i need to loop it and am not aware of a straightforward copy.
some dirty trick to copy across namespace boundaries:
have a target class config but change the global references in STORAGE section from
^Package.ClassD and ^Package.ClassI to
^
|"namespace"|
Package.ClassD and ^|"namespace"|
Package.ClassIMight be a different way to work across namespaces
Hi @Jimmy Christian ,
Thanks to @Robert.Cemper for the "INSERT ...... SELECT .... " command.
You can find more help in the following link https://www.w3schools.com/sql/sql_insert_into_select.asp
Hope this helps.