Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello Friends....!!!

I have a Database in which some numbers are in 10 column.

I want to increment a users 2nd column by 1, third column by 4 , fourth column by 3 and 5th column by 6 etc....

Now i am using this logic....

1). I will retrieve values in variables from database
2) Increment in these variables
3). Update the data base




Please help me i am new here !!!!!
Posted
Updated 11-Jan-13 0:38am
v2
Comments
Amir Mahfoozi 25-Dec-11 4:19am    
It seems that a bad designed table beside a bad designed application going to mix together. If it is a serious project leave it to a skilled one but if it is a home work try to analyze the problem with some consultation from an expert. Excuse me that I was so frank.
Pr!y@ 25-Dec-11 12:38pm    
Yes you are right but i will tell you soon that i have created a good website,
i hope so,,,,,
Amir Mahfoozi 25-Dec-11 12:52pm    
I hope so too, And I will be very glad to hear that ;) Good Luck. :)
Pr!y@ 26-Dec-11 0:26am    
Thanks Sir
Amir Mahfoozi 26-Dec-11 2:07am    
Your language is very near to Farsi :)
But OK I got it. Here is the right place to ask but I meant that you need to experience and study more.
Good Luck ;)

I would write a stored procedure to do it: that way it is all done within the database, and there is no risk of other people doing the same thing, and you ending up with wrong values.
SQL
USE [myDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [proc_addtovals]
AS
UPDATE myTable SET column2=column2+1, column3=column3+4
 
Share this answer
 
Never change the values via irrelevant controls. As OriginalGriff showed, you can set the increment values to the SQL statement and let the database do the calculations.

If the amount of increment is user defined, then use parameters to define the increment:
SQL
UPDATE TableName SET Field1 = Field1 + @increment;

See: SqlParameter[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900