Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sunny_10
Yak Posting Veteran
72 Posts |
Posted - 2012-11-18 : 05:36:03
|
Hi I want to loop through all records in a table & then update some fields of the same record doing calculations of some fields of same record. I want this through Stored ProcedureThanks |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2012-11-18 : 08:15:41
|
quote: Originally posted by sunny_10 Hi I want to loop through all records in a table & then update some fields of the same record doing calculations of some fields of same record. I want this through Stored ProcedureThanks
I want folks to actually ask a question when they want a response. And to include enough details about their problem for use to answer it. But reading into your statement:Don't think "loops" think "sets". a simple update statement sounds like all you need. Something like this:update mt from <myTable> as mt set mt.col5 = mt.col1 + mt.col2That statement will update column [col5] for ALL rows in your table with the calculation results of col1+col2EDIT:and to turn that into a stored procedure:create procedure myProc as<statement(s)>goBe One with the OptimizerTG |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-19 : 01:34:14
|
if you want this to happen automatically on each insert make columns computed with formulas referring the other base fields------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|