Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to increment the value of cells in SQL Server 2008
ex.
date | name | money | address
4  | men  |  10   | new york
1  | fmale|  50   | USA
3  | jef  |  60   | JAPAN
3  | jef  |  60   | JAPAN
3  | jef  |  60   | JAPAN


I want the out looks like this
date | name | money | address
4  | men  |  10   | new york
1  | fmale|  50   | USA
3  | jef  |  60   | JAPAN
3  | jef  |  70   | JAPAN
3  | jef  |  80   | JAPAN


what i want is that. the table will look for the last number found in money (e.g. fmale money 50) so all jef money will increment by 10.it will looks like the second illustration? how to code that in sql server?
Posted
Updated 25-Jul-13 0:42am
v2
Comments
NPSSR 25-Jul-13 6:37am    
Kindly write it more clear to help me to help you.
Maciej Los 25-Jul-13 6:43am    
Agree.
Gishisoft 25-Jul-13 20:15pm    
ok. I will make it simpler for you. what is the last display number in money. the next row inserted will increment by 10. so assuming the fmale will be the last inserted since the money she/he had was 50, so what i want for the next inserted rows will increment by 10. and that is jef.
Gishisoft 25-Jul-13 20:18pm    
to make it not complicated. just remove 4|men|10|new york. to make it easier for us to understand. :)
gvprabu 25-Jul-13 7:47am    
yes correct, If one more name is there after "jef" then hsi money is 20 then we need to show as 20+10 as 30 like this it will continue or "jef" last record is 80 so next person's money value will start with 80+10 as 90...?

1 solution

Use Identity Specification on Money column; with the seed as 10 and increment as 10...
Then you may start inserting rows(omit Money) and Money will get incremented automatically.

http://msdn.microsoft.com/en-us/library/ms186775(v=sql.100).aspx[^]
 
Share this answer
 
v3
Comments
Maciej Los 25-Jul-13 11:03am    
I'm afraid your solution is wrong ;(
Please, carefully read question and comments to the question...
Gishisoft 25-Jul-13 20:12pm    
what is the right answer?
Kuthuparakkal 26-Jul-13 0:42am    
Use IDENTITY, see my soln updated!
Gishisoft 26-Jul-13 1:24am    
pls vote up my question. and i will accept your answer. i got already the answer and since you are working hard for your answer. i will accept your answer!
Gishisoft 26-Jul-13 1:24am    
your answer is almost same as mine. tnx for your help too!

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