September 2, 2009 at 2:20 pm
Hi!
I dont know why this trigger aint working.
Scenario:
Data gets inserted, trigger gets fired, i take all the data from INSERTED and then inserted back in the same table with a new value.
this is what i´ve got.
create trigger one on dbo.pedidos
after insert as
begin
set nocount on;
INSERT INTO dbo.pedidos
([PedNum]
,[CotNum]
,[SCodAux]
,[PedContacto]
,[PedComuID]
,[PedComuNom]
,[PedCiuID]
,[PedCiuNom]
,[PedVenID]
,[PedVenNom]
,[PedFechaCot]
,[PedGlosaCot]
,[PedFechaSolEje]
,[PedOrdCompra]
,[PedContrato]
,[PedObs]
,[ESTID])
select
(inserted.PedNum,
inserted.[CotNum],
inserted.[SCodAux],
inserted.[PedContacto],
inserted.[PedComuID],
inserted.[PedComuNom],
inserted.[PedCiuID],
inserted.[PedCiuNom],
inserted.[PedVenID],
inserted.[PedVenNom],
inserted.[PedFechaCot],
inserted.[PedGlosaCot],
inserted.[PedFechaSolEje],
inserted.[PedOrdCompra],
inserted.[PedContrato],
inserted.[PedObs],
'2')
end
September 2, 2009 at 2:37 pm
igngua (9/2/2009)
I dont know why this trigger aint working.
What do you mean by 'not working'? What's it not doing that it should be?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 2, 2009 at 2:39 pm
Is thr FROM clause ommited or missing?
igngua (9/2/2009)
Hi!I dont know why this trigger aint working.
Scenario:
Data gets inserted, trigger gets fired, i take all the data from INSERTED and then inserted back in the same table with a new value.
this is what i´ve got.
create trigger one on dbo.pedidos
after insert as
begin
set nocount on;
INSERT INTO dbo.pedidos
([PedNum]
,[CotNum]
,[SCodAux]
,[PedContacto]
,[PedComuID]
,[PedComuNom]
,[PedCiuID]
,[PedCiuNom]
,[PedVenID]
,[PedVenNom]
,[PedFechaCot]
,[PedGlosaCot]
,[PedFechaSolEje]
,[PedOrdCompra]
,[PedContrato]
,[PedObs]
,[ESTID])
select
(inserted.PedNum,
inserted.[CotNum],
inserted.[SCodAux],
inserted.[PedContacto],
inserted.[PedComuID],
inserted.[PedComuNom],
inserted.[PedCiuID],
inserted.[PedCiuNom],
inserted.[PedVenID],
inserted.[PedVenNom],
inserted.[PedFechaCot],
inserted.[PedGlosaCot],
inserted.[PedFechaSolEje],
inserted.[PedOrdCompra],
inserted.[PedContrato],
inserted.[PedObs],
'2')
FROM Inserted
end
September 2, 2009 at 2:41 pm
it says syntax error.
create trigger one on dbo.pedidos
after insert as
begin
set nocount on;
INSERT INTO dbo.pedidos(PedNum,ESTID)
select(inserted.PedNum,'2')
from inserted
end
dont know what i´m missing.
September 2, 2009 at 2:43 pm
thanks!! i corrected it, it didnt work also...it i´m gonna do it all over again.
September 2, 2009 at 2:48 pm
igngua (9/2/2009)
it says syntax error.
Brackets around the select shouldn't be there.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 2, 2009 at 2:53 pm
Shortened up the list of columns but this select works, just addin all the column names that I skipped over to make testing quick and easier.
INSERT INTO dbo.pedidos ([PedNum],[ESTID])
select PedNum, '2' FROM inserted
end
September 2, 2009 at 5:26 pm
Go ahead and remove the paretheses from your select clause
instead of
select
(inserted.PedNum,
...
inserted.[PedObs],
'2')
select
inserted.PedNum,
...
inserted.[PedObs],
'2'
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 3, 2009 at 7:46 am
thanks for the help guys.
Now another thing...
the triggers does what is supposed to...but one of the rows is PK, so the trigger cant insert the data from inserted in the original table because its already there.
Is there anyway i can do this, keeping the row as a PK?
here is the working trigger.
create trigger insertaestadopendiente on dbo.pedidos
after insert as
begin
set nocount on;
INSERT INTO dbo.pedidos
[PedNum] --this is PK--
,[ESTID])
select
inserted.PedNum,
'2'
from inserted
end
thanks in advance.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply