Hello to all,
I have two questions.
Question number 1: I have a problem using the "case" operator. Initially I wrote 6 "update" statements to be executed on different boolean conditions , and then I figured out it would be more productive to change it to one update statement using "case" . Unfortunately , after I made this changement the code doesn't work anymore and I don't know why.
The structure of the update I wrote is the following:
update Tbl_Commission
set Commission=
CASE
when com.regular_good='S'andsal.SalesrepCode=com.SalesRepNumber
then ExtPrice*sal.CommSpecialItems
when com.regular_good<>'S'and com.Steady<>'S'and Price_level=1 and sal.SalesrepCode=com.SalesRepNumber
then ExtPrice*sal.CommNonStItemsL1
...
END
from Tbl_Commission com,tblSalesrep sal
--None of the case options is ever executed , how comes? Is the case really executed on each record from Tbl_commission table?
Question 2 : How can I in sqlserver return record by record from a table . Which type of pointer/variables should I use ?
I have two questions.
Question number 1: I have a problem using the "case" operator. Initially I wrote 6 "update" statements to be executed on different boolean conditions , and then I figured out it would be more productive to change it to one update statement using "case" . Unfortunately , after I made this changement the code doesn't work anymore and I don't know why.
The structure of the update I wrote is the following:
update Tbl_Commission
set Commission=
CASE
when com.regular_good='S'andsal.SalesrepCode=com.SalesRepNumber
then ExtPrice*sal.CommSpecialItems
when com.regular_good<>'S'and com.Steady<>'S'and Price_level=1 and sal.SalesrepCode=com.SalesRepNumber
then ExtPrice*sal.CommNonStItemsL1
...
END
from Tbl_Commission com,tblSalesrep sal
--None of the case options is ever executed , how comes? Is the case really executed on each record from Tbl_commission table?
Question 2 : How can I in sqlserver return record by record from a table . Which type of pointer/variables should I use ?