I have a trigger that works on one instance (windows platform GUI) but not in the Web platform (GUI)
My trigger is below:
create trigger [dbo].[Trig] on [dbo].[AMGR_Opportunity_Tbl] after insert
asBEGIN
Declare @Opp_id varchar (24)
Declare @OppNo int
Declare @Opp_type int
DECLARE @NewQno VARCHAR(750)
declare @Qno varchar (50)select @Opp_id = client_id from INSERTED;
Select @OppNo = Contact_number from INSERTED;
Select @Opp_type = Opp_type from inserted;SELECT @NewQno = Convert(VARCHAR(750), Convert(INT, Qno) + 1)
FROM T1 WHERE ID = 1;If @Opp_type = '0'
SELECT @NewQno = Convert(VARCHAR(750), Convert(INT, Qno) + 1)
FROM T1 WHERE ID = 1;if exists (select * from O_QUDF where Client_Id = @Opp_id)
update O_QUDF set O_QUDF = @NewQno
else
INSERT INTO O_QUDF(Client_id,Contact_Number,Type_Id,Code_Id,O_QUDF)
values(@Opp_id,@OppNo,110,0,@NewQno)UPDATE T1 SET Qno = @NewQno WHERE ID = 1
End
GO
I need to add in a check to see if the values being inserted are there or not. The error i am getting on the web interface is a foreign key contraint duplication.
the procedure of this trigger should work as follows:
- Trigger fired on Opportunity table when Opp type = 0 only
- Calculation to pick up last number used (in table T1)
- Add 1 to last number used in T1
- Insert the last number used into the column O_QUDF in the O_QUDF table
- update Table T1 to record last number used.
As far as i can see i think i am following the logic above however it isnt working as it should.
Each time an opportunity is inserted into the Opportunity table with opp_type = 0, then the trigger should fire and do the above logic..
As i said, it works in the windows application GUI not on the web. i just cant seem to get this code right after getting numerous examples on various forums.. If someone can point me in the right direction as to what i can try. i would greatly appreciate it.