SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sunny_10
Yak Posting Veteran

63 Posts

Posted - 11/18/2012 :  05:36:03  Show Profile  Reply with Quote
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 Procedure

Thanks

TG
Flowing Fount of Yak Knowledge

USA
5932 Posts

Posted - 11/18/2012 :  08:15:41  Show Profile  Reply with Quote
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 Procedure

Thanks


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.col2

That statement will update column [col5] for ALL rows in your table with the calculation results of col1+col2

EDIT:
and to turn that into a stored procedure:

create procedure myProc as
<statement(s)>
go

Be One with the Optimizer
TG

Edited by - TG on 11/18/2012 08:17:55
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/19/2012 :  01:34:14  Show Profile  Reply with Quote
if you want this to happen automatically on each insert make columns computed with formulas referring the other base fields

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000