473,473 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trigger does not affect the code written in the loop... pls help its urgent

5 New Member
I want to create a trigger wherein with every insert on paymentdetails table the individual commission should be calculated for a particular agent based on his rank and the premium amt. At the same time group commission should be calculated for the subsequent Introducers in the hierarchy and all agents & Introducers commission should be stored in AgentComm table. I hav written d trigger for it but it gives me only the agents commission and not the introducers and the introducer's introducer details.. Can someone please solve this query.
Following are my tables and the code which I have written



create table paymentdetails
(MemberNo int,
LicenseNo int,
PremiumAmt money)

create table Agent
(LicenseNo int,
IntroducersLicNo int,
Rank int
)

create table Rank
(
Rank int,
IComm float,
GComm float
)

create table AgentComm
(
LicenseNo int,
MemberNo int,
Commission money
)

create trigger comm on paymentdetails
for insert
as
declare @LicNo int
declare @NextLicNo int
declare @MemberNo int
declare @Premium int
declare @Introducer int
declare @Rank int
declare @Comm float
declare @CalcComm money

declare @IntLic int
declare @IntRank int
declare @IntIntroducer int
declare @IntComm float
declare @CalculateComm money

select @LicNo= (select LicenseNo from inserted)
select @MemberNo=(select MemberNo from inserted)
select @Premium=(select PremiumAmt from inserted)
select @Rank=(select Rank from Agent where LicenseNo=@LicNo)
select @Comm=(select (IComm/100) from Rank where Rank=@Rank)
select @Introducer=(select IntroducersLicNo from Agent where LicenseNo=@LicNo)
select @CalcComm=@Comm*@Premium

insert into AgentComm (LicenseNo,MemberNo,Commission)
values (@LicNo,@MemberNo,@CalcComm)

select @NextLicNo=@Introducer

while(@NextLicNo<>NULL)
begin
select @IntLic=(select LicenseNo from Agent where LicenseNo=@NextLicNo)
select @IntIntroducer=(select IntroducersLicNo from Agent where LicenseNo=@IntLic)
select @IntRank=(select Rank from Agent where LicenseNo=@IntLic)
select @IntComm=(select (GComm/100) from Rank where Rank=@IntRank)
select @CalculateComm=@IntComm*@Premium

insert into AgentComm (LicenseNo,MemberNo,Commission)
values (@IntLic,@MemberNo,@CalculateComm)

select @NextLicNo=@IntIntroducer
end
Feb 12 '07 #1
2 1452
Tian
5 New Member
I want to create a trigger wherein with every insert on paymentdetails table the individual commission should be calculated for a particular agent based on his rank and the premium amt. At the same time group commission should be calculated for the subsequent Introducers in the hierarchy and all agents & Introducers commission should be stored in AgentComm table. I hav written d trigger for it but it gives me only the agents commission and not the introducers and the introducer's introducer details.. Can someone please solve this query.
Following are my tables and the code which I have written



create table paymentdetails
(MemberNo int,
LicenseNo int,
PremiumAmt money)

create table Agent
(LicenseNo int,
IntroducersLicNo int,
Rank int
)

create table Rank
(
Rank int,
IComm float,
GComm float
)

create table AgentComm
(
LicenseNo int,
MemberNo int,
Commission money
)

create trigger comm on paymentdetails
for insert
as
declare @LicNo int
declare @NextLicNo int
declare @MemberNo int
declare @Premium int
declare @Introducer int
declare @Rank int
declare @Comm float
declare @CalcComm money

declare @IntLic int
declare @IntRank int
declare @IntIntroducer int
declare @IntComm float
declare @CalculateComm money

select @LicNo= (select LicenseNo from inserted)
select @MemberNo=(select MemberNo from inserted)
select @Premium=(select PremiumAmt from inserted)
select @Rank=(select Rank from Agent where LicenseNo=@LicNo)
select @Comm=(select (IComm/100) from Rank where Rank=@Rank)
select @Introducer=(select IntroducersLicNo from Agent where LicenseNo=@LicNo)
select @CalcComm=@Comm*@Premium

insert into AgentComm (LicenseNo,MemberNo,Commission)
values (@LicNo,@MemberNo,@CalcComm)

select @NextLicNo=@Introducer

while(@NextLicNo<>NULL)
begin
select @IntLic=(select LicenseNo from Agent where LicenseNo=@NextLicNo)
select @IntIntroducer=(select IntroducersLicNo from Agent where LicenseNo=@IntLic)
select @IntRank=(select Rank from Agent where LicenseNo=@IntLic)
select @IntComm=(select (GComm/100) from Rank where Rank=@IntRank)
select @CalculateComm=@IntComm*@Premium

insert into AgentComm (LicenseNo,MemberNo,Commission)
values (@IntLic,@MemberNo,@CalculateComm)

select @NextLicNo=@IntIntroducer
end

Please help..Its vry urgent
Feb 13 '07 #2
reon
80 New Member
Expand|Select|Wrap|Line Numbers
  1. select @LicNo= (select LicenseNo from inserted)
the above select u want to replace it with set that is the mistake...
select means you are just selecting from that inserted table but set means you are setting it to some other values......
replace that select with set ..ok


I want to create a trigger wherein with every insert on paymentdetails table the individual commission should be calculated for a particular agent based on his rank and the premium amt. At the same time group commission should be calculated for the subsequent Introducers in the hierarchy and all agents & Introducers commission should be stored in AgentComm table. I hav written d trigger for it but it gives me only the agents commission and not the introducers and the introducer's introducer details.. Can someone please solve this query.
Following are my tables and the code which I have written



create table paymentdetails
(MemberNo int,
LicenseNo int,
PremiumAmt money)

create table Agent
(LicenseNo int,
IntroducersLicNo int,
Rank int
)

create table Rank
(
Rank int,
IComm float,
GComm float
)

create table AgentComm
(
LicenseNo int,
MemberNo int,
Commission money
)

create trigger comm on paymentdetails
for insert
as
declare @LicNo int
declare @NextLicNo int
declare @MemberNo int
declare @Premium int
declare @Introducer int
declare @Rank int
declare @Comm float
declare @CalcComm money

declare @IntLic int
declare @IntRank int
declare @IntIntroducer int
declare @IntComm float
declare @CalculateComm money

select @LicNo= (select LicenseNo from inserted)
select @MemberNo=(select MemberNo from inserted)
select @Premium=(select PremiumAmt from inserted)
select @Rank=(select Rank from Agent where LicenseNo=@LicNo)
select @Comm=(select (IComm/100) from Rank where Rank=@Rank)
select @Introducer=(select IntroducersLicNo from Agent where LicenseNo=@LicNo)
select @CalcComm=@Comm*@Premium

insert into AgentComm (LicenseNo,MemberNo,Commission)
values (@LicNo,@MemberNo,@CalcComm)

select @NextLicNo=@Introducer

while(@NextLicNo<>NULL)
begin
select @IntLic=(select LicenseNo from Agent where LicenseNo=@NextLicNo)
select @IntIntroducer=(select IntroducersLicNo from Agent where LicenseNo=@IntLic)
select @IntRank=(select Rank from Agent where LicenseNo=@IntLic)
select @IntComm=(select (GComm/100) from Rank where Rank=@IntRank)
select @CalculateComm=@IntComm*@Premium

insert into AgentComm (LicenseNo,MemberNo,Commission)
values (@IntLic,@MemberNo,@CalculateComm)

select @NextLicNo=@IntIntroducer
end
Feb 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Lauren Quantrell | last post by:
I have never written a trigger before and now am seeing the light. Is there a way to write a trigger so that if a user changes any column in a single row on one table then the trigger will write...
33
by: coosa | last post by:
I have a table: ---------------------------------------------------- CREATE TABLE CATEGORY ( CATEGORY_ID INTEGER IDENTITY(1,1) NOT NULL, CATEGORY_NAME VARCHAR(40) NOT NULL,...
16
by: Josué Maldonado | last post by:
Hello list, The TCL trigger that uses NEW and OLD arrays failed after after I removed a unused column, now I got this error: pltcl: Cache lookup for attribute '........pg.dropped.24........'...
13
by: Tolik Gusin | last post by:
Hello All, DB2 UDB 8.1 FP3 for Linux The table has 4 triggers on the Insert operation. Three triggers small (200 bytes) and one trigger large (3 ËÂ). In the large trigger there is one long...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
3
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the...
6
by: JohnO | last post by:
Hi Folks, I have an update trigger that fails (it inserts an audit table record) in some circumstances. This is causing the triggering transaction to fail and roll back. Is there any way to...
2
by: D. Dante Lorenso | last post by:
I'm trying to build a table that will store a history of records by enumerating the records. I want the newest record to always be number ZERO, so I created a trigger on my table to handle the...
3
by: Mae Lim | last post by:
Hi All, I've a problem here, I want to trigger a javascript function after binding the ListBox control. Basically the javascript will remove the duplicates records after recordset is bind in the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.