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)
 how to use cursor

Author  Topic 

putane.sanjay
Yak Posting Veteran

77 Posts

Posted - 2006-12-11 : 08:34:57
iam new sql server database if i want update salaries for below conditions how to write cursor for this

update salary 2000 whose sal between 5000 to 10000
update salary 3000 whose sal between 10000 to 15000
update salary 5000 whose sal between 15000 to 20000

please help me

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-11 : 08:38:46
CURSOR?
UPDATE YourTableNameHere
SET Salary = CASE
WHEN Salary BETWEEN 5000 AND 9999 THEN 2000
WHEN Salary BETWEEN 10000 AND 14999 THEN 3000
WHEN Salary BETWEEN 15000 AND 19999 THEN 5000
ELSE 0
END + Salary


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-11 : 08:39:51
Or
UPDATE YourTableNameHere
SET Salary = CASE
WHEN Salary BETWEEN 5000 AND 9999 THEN 2000
WHEN Salary BETWEEN 10000 AND 14999 THEN 3000
WHEN Salary BETWEEN 15000 AND 19999 THEN 5000
END + Salary
WHERE Salary BETWEEN 5000 AND 19999


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-12-11 : 13:56:15
Or:
UPDATE YourTableNameHere
SET Salary = CASE
WHEN Salary <10000 THEN 2000
WHEN Salary <15000 THEN 3000
ELSE 5000
END + Salary
WHERE Salary BETWEEN 5000 AND 19999
Go to Top of Page

putane.sanjay
Yak Posting Veteran

77 Posts

Posted - 2006-12-12 : 03:07:12
thank u for ur suggestions
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-12 : 03:08:48
I hope we didn't upset your professor with this alternative solution...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -