This is a discussion on Update the value back within the Database Support forums, part of the Web Development category; Hi there, I'm new to SQL Server 2005 and stored procedure. I want a simple logic to be done ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi there, I'm new to SQL Server 2005 and stored procedure. I want a simple logic to be done using store procedure. I select a field from a table with multiple rows of records, then later I update the value back to the same field after calculation. How can i do that? |
| Sponsored Links |
| |||
| Hey Leo, Use my coding as following, Code: Declare MyCur Cursor
For
Select name,age From emp --- your query here
Open MyCur
Declare @UserName Varchar(50)
Declare @Age int
Fetch Next From Cursor Into @UserName, @Age
While @@Fetch_Status = 0
Begin
Update emp set age = @Age *2 where [name]= @UserName -- do your calculation here
End
Close MyCur
Deallocate MyCur
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Hi there, I think the cursor is not necessary here. For all records in the table: Code: UPDATE employee SET age = age + 1 or, if we are being more precise: Code: UPDATE employee SET pay_grade = pay_grade + 1 WHERE department = 'Sales'
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
| |||
| So...have a glad for your problem solved. ![]()
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! Last edited by S.Vinothkumar : 09-28-2007 at 11:36 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Back Links and PR Update | muller | 1 | 09-29-2008 05:34 AM | |
| Great to be back! | WiccanSpirit | The Lounge | 4 | 02-18-2008 02:23 AM |
| Back End testing | simplesabita | Software Testing | 1 | 10-30-2007 03:49 AM |
| BACK inAjax | jegan | PHP Programming | 2 | 08-06-2007 03:49 AM |
| Disable Back Button | ewriter | HTML, CSS and Javascript Coding Techniques | 1 | 04-24-2007 11:16 PM |