I have two table “TempStore” and “Store” with the same column called “Items”.
There is data in “TempStore” table which I need to move over to “Store” table which requires few modifications.
I need to iterate over “TempStore” data (i.e. items) and insert into Store…
More specifically: How can I iterate over TempStore (in sql) where “for each item in ‘TempStore’ I need to store 2 or maybe 3 items in ‘Store’ with little modification”, how can I accomplish this?
What I want to do is take each rowdata from “[SELECT * FROM TempStore]” and insert three records in “Store” with being able to change “items”
try INSERT-SELECT:
just make the SELECT return one row for every insert, and produce the values in the Cols that you need. You might need
CASEand a join to another table to make the extra rows.EDIT based on comments, OP wanted to see the numbers table in action
you could even use a UNION:
either the Numbers table or the UNION will we WAY better than a loop!