SQL Server stored procedure - SELECT statement then use results in INSERT statement -


i writing stored procedure results 1 table copy them another. isn't exact match, i'm changing 1 column , ignoring another. there 5 columns , on average 3-5 results if relevant.

i need to:

select * sometable somecolumn = 1 

then every result

insert anothertable (a,b,c) values (@a, @b, @c) 

what best way within stored procedure?

you can in 1 statement:

insert anothertable (a, b, c) select a, b, c sometable somecolumn = 1 

wherever possible, avoid doing things in loops/cursors/rbar (row agonizing row) , instead try think in set-based approaches above.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -