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.
Author |
Topic |
dlmagers10
Starting Member
48 Posts |
Posted - 2010-12-02 : 14:34:35
|
I need to add a customer, add the customer's balance (*) the sales rep's commission rate to the commission for the corresponding sales rep.Here is what I have already:--create trigger add_customer--on customer--after insert--as----declare @balance decimal(8,2)--select @balance = (select balance from inserted)--update rep--set on_customer = balance * rateTablescustomer:customer_numcustomer_namestreetcitystatezipbalancecredit_limitrep_numrep:rep_numlast_namefirst_namestreetcitystatezipcommissionrate**Honestly, I am stumbed on this one. Triggers are something new to me. Yes, I am just learning at a beginners stage.**If there is any references that someone can direct me to or look at what I have already and give advise that would be a big help. Thank you for your time. I appreciate any help with this one. |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-12-02 : 16:12:51
|
Why are you looking to store info about the customer in the rep table? What happens if there's more than one customer associated with the rep?The on_customer that you list in the trigger doesn't exist in the rep table (and shouldn't). Or do you mean a different column?What's the relationship between customer and rep? If there's more than one rep, how do we know which one gets the commission? All of them?As for the trigger code, what happens if there's more than one row updated in a single operation?--Gail ShawSQL Server MVP |
 |
|
|
|
|