This is part of my program where I need to save in a table called ventas_n two columns: cve_art (product_code) and cve_alterna (alternative_code)
Later on I have to use this table in another query.
//MSSQLConnection1 is a TMSSQLConnection; connection to ms sql server
//SQLQuery1 is a TSQLQuery
//SQLQuery2 is a TSQLQuery
//SQLQuery1 has selected lots of records (about 5,000) from three (3) diffrent tables (facturas, remisiones y devoluciones -invoices, delivery notes and returns)
...
// Delete any previous records in ventas_n,,.
SQLQuery2.Close;
SQLQuery2.DataBase := MSSQLConnection1;
SQLQuery2.SQL.Text := 'delete from ventas_n;';
SQLQuery2.ExecSQL;
SQLQuery1.First;
SQLQuery2.SQL.Text := 'insert into ventas_n (cve_art, cve_alterna) values (:value1,:value2)';
While Not(SQLQuery1.EOF) do
begin
c_art := SQLQuery1.FieldByName('cve_art').AsString;
c_alter := SQLQuery1.FieldByName('alterna').AsString;
SQLQuery2.Params.ParamByName('value1').AsString := c_art;
SQLQuery2.Params.ParamByName('value2').AsString := c_alter;
try
SQLQuery2.Close;
SQLQuery2.ExecSQL;
finally
// No additional action to be taken
end;
cant_reg := cant_reg + 1;
SQLQuery1.Next;
end;
...
You can imagine that going through the whole SQLQuery1 by: While Not(SQLQuery1.EOF) do begin ... end takes some time, and I would like to try another approach.
I have read that a) select ... into table_b from table_a is desirable comapred to b) insert into table_b (...) SELECT ... from table_a ...
I know in my case I do not have two tables, as a source I have a dataset. But I was wondering if there is another possible way to do it. Any suggestions? Thanks a lot.