IT Community - Software Programming, Web Development and Technical Support

Update the value back

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


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-25-2007, 11:51 PM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Question Update the value back

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?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-26-2007, 03:38 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: Update the value back

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-27-2007, 03:03 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Cool Re: Update the value back

Hi there,

I think the cursor is not necessary here.

For all records in the table:
Code:
UPDATE employee
SET age = age + 1
this will increment all employee ages by one.

or, if we are being more precise:
Code:
UPDATE employee
SET pay_grade = pay_grade + 1
WHERE department = 'Sales'
this will increase the pay grade for all sales employees.
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-27-2007, 03:49 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Wink Re: Update the value back

thnx vinoth,

It's work for my wish....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-27-2007, 04:21 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: Update the value back

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Back Links and PR Update muller Google 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


All times are GMT -7. The time now is 09:17 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0