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
 Transact-SQL (2000)
 using cursors to check each record for a specific condn

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-15 : 07:48:06
Tina writes "hi,

I have to copy data from a file to a temporay table & from there to the original table. I have used a procedure to do the same. I need to use a cursor to fetch each record from the temp table check for the below given conditions, update it & then enter it in the original table :
If job is CLERK then commission is 5% of salary
If job is MANAGER then commission is 10% of salary
If job is DEPUTY MANAGER then commission is 15% of salary
How do i write a cursor in the procedure & chk for the condition?
can i use multiple if-then or any other way? plz suggest"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-08-15 : 07:50:35
Sorry, this is SQL Team, we don't know how to write cursors:

UPDATE myTable
SET Commission=CASE JobTitle
WHEN 'CLERK' THEN Salary * 0.05
WHEN 'MANAGER' THEN Salary * 0.10
WHEN 'DEPUTY MANAGER' THEN Salary * 0.15
ELSE Comission END


That will update all of the rows and do the calculations you've specified. If this will not work for you you will need to post your code and table structures so we can refine the answer.
Go to Top of Page
   

- Advertisement -