I am writing a stored procedure that will get results from one table then copy them to another. It isn’t an exact match, I’m changing 1 column and ignoring another. There are 5 columns and on average 3-5 results if that is relevant.
I basically need to:
SELECT * FROM sometable WHERE somecolumn = 1
Then for every result
INSERT INTO anothertable (a,b,c) VALUES (@a, @b, @c)
What is the best way to do this within a stored procedure?
You can do this in one statement:
Wherever possible, avoid doing things in loops/cursors/RBAR (Row By Agonizing Row) and instead try to think in SET-based approaches like above.