Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 stored procedures for updating

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2002-04-10 : 16:24:25
I am trying to write a stored procedure to update a table in my database each night. What I want it to go do is look at a column and depending on the information on it update it once. Here is the info on the table and column:
Table Name: dragonballs
Column name: earth
Column start info: 1/21
I want it to go out and look to see if it says 1/21 and if it does to change it to 2/21, if it does not to see if it says 2/21 and if it does to change it to 3/21. And so on.

Any ideas on how to do this would be very helpful (please if possible include and example code)
Thanks.

motokevin
Starting Member

36 Posts

Posted - 2002-04-10 : 16:58:40
if you just want to increment by 1 regardless, then do this:

Update dragonballs
Set earth = earth + 1/21

this will update the whole table.

if you have more conditions involved, then do this:

Update dragonballs
Set earth = CASE earth
WHEN 1/21 THEN 2/21
WHEN 2/21 THEN 3/21
WHEN 3/21 THEN 4/21
etc.......
END

this will update earth differently depending on its current value.

Good Luck.


Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2002-04-10 : 17:24:09
Motokevin,
Thank you SO much, I just tested the case code you provided and it work perfectly! I have been trying to do it for almost 4 day, and thanks to you this SQL newbee can do what he wanted. Again thank you SO much! You Rule!

Go to Top of Page
   

- Advertisement -