HI There..
This is what i am trying to do:
I have a sales opportunity (or deal) and when i insert or change the stage of this opportunity, this table has multiple columns however i only want the stage to be inserted into another table or field. The other field is called OppsStage and the columns here are:
Column 1 - client_id
Column 2 - OppStage
Column 3 - Type_id
I am new at these triggers, i have only done one that is of a similar concept. (creates a new quote number when a new opportunity is created) but now i need assistance on how to achieve the above with the stages..
I dont know if i must use something like the below:
Declare @Stage varchar (50)
BEGIN
SET ROWCOUNT 0
SET NOCOUNT ONIF EXISTS (SELECT 1
FROM Opp_View
WHERE Stage = @Stage)
BEGIN
SET @Stage = 'Not Started';
END
ELSE
BEGIN
SET @Stage = 'Communication';
ENDif @Stage = 'not started'
INSERT INTO O_OppStage(Client_id,Contact_Number,O_OppStage)
SELECT inserted.Opp_Id, 0, @Stage
FROM inserted inner join Opp_View B on inserted.Opp_Id = b.Opp_Id
WHERE inserted.Opp_Type = 0
and @Stage = 'Not Started'
else if @Stage = 'Initial communication'
INSERT INTO O_OppStage(Client_id,Contact_Number,O_OppStage)
SELECT inserted.Opp_Id, 0, @Stage
FROM inserted inner join Opp_View B on inserted.Opp_Id = b.Opp_Id
WHERE inserted.Opp_Type = 0
and @Stage = 'Initial communication'
end
end
or if i must do this approach, with if stage = 'not started' then insert into ..
The goal is to achieve the following:
When the stage is inserted into a new row in the opportunities table, that stage is also inserted into the other table.
So like a mirror..
so if stage = stage 1 in the opportunities table then stage in table O_OppStage also needs to be stage 1
Any guidance would be greatly appreciated