Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Trigger


Trigger

Author
Message
crazy_new
crazy_new
SSC-Enthusiastic
SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)

Group: General Forum Members
Points: 187 Visits: 365
Hi,

Can anyone please help my with the following trigger.

ALTER TRIGGER [dbo].[PAT_2_AJS]

ON [dbo].[INVOICE_HEADER]

FOR INSERT
AS

BEGIN
EXECUTE sp_PAT_2_AJS_TEST
END
GO


When I execute the trigger it says command successful and when I execute Just the one line - EXECUTE sp_PAT_2_AJS_TEST it works,
but when I insert data through the front end the trigger doesn't work.
When I use the code in the SP instead of execute sp_PAT_2_AJS_TEST it also works..

Why is this?
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47239 Visits: 44377
Define 'doesn't work'?

What does that procedure do? What's the trigger supposed to do? Why is the trigger not referencing inserted or deleted pseudo-tables at all?


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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


crazy_new
crazy_new
SSC-Enthusiastic
SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)

Group: General Forum Members
Points: 187 Visits: 365
The SP inserts data into a table in another database.
The trigger should execute this stored procedure as soon as new data is inserted into the table.
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47239 Visits: 44377
Ok, and...?

With the trigger as you have posted it, any insert will fire that trigger and hence will run that procedure. Whether it works as intended is another matter, but I can't tell that without knowing what the procedure does (specifics, not a one-line description) and what it's intended to do.


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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


crazy_new
crazy_new
SSC-Enthusiastic
SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)

Group: General Forum Members
Points: 187 Visits: 365
The stored procedure works, because if I execute it outside the trigger, it works.

Maybe my syntax is wrong for the trigger or something
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14956 Visits: 38952
crazy_new (1/28/2014)
The stored procedure works, because if I execute it outside the trigger, it works.

Maybe my syntax is wrong for the trigger or something


apparently, the stored procedure finds the data it's supposed to touch all by itself, since it has no parameters.

most likely, whatever code is inside that procedure should exist inside the trigger INSTEAD, and it should reference the INSERTED and DELETED virtual tables inside the trigger, as Gail suggested.

unless you post the actual code for your proc, we cannot help you.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Greg Edwards-268690
Greg Edwards-268690
SSC Eights!
SSC Eights! (817 reputation)SSC Eights! (817 reputation)SSC Eights! (817 reputation)SSC Eights! (817 reputation)SSC Eights! (817 reputation)SSC Eights! (817 reputation)SSC Eights! (817 reputation)SSC Eights! (817 reputation)

Group: General Forum Members
Points: 817 Visits: 8257
Lowell (1/28/2014)
crazy_new (1/28/2014)
The stored procedure works, because if I execute it outside the trigger, it works.

Maybe my syntax is wrong for the trigger or something


apparently, the stored procedure finds the data it's supposed to touch all by itself, since it has no parameters.

most likely, whatever code is inside that procedure should exist inside the trigger INSTEAD, and it should reference the INSERTED and DELETED virtual tables inside the trigger, as Gail suggested.

unless you post the actual code for your proc, we cannot help you.


+1
apparently, the stored procedure finds the data it's supposed to touch all by itself, since it has no parameters.

that is an interesting reaction related to new data.
You inserted a record, do something.
Insert a Date Time Stamp in the other table?
crazy_new
crazy_new
SSC-Enthusiastic
SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)

Group: General Forum Members
Points: 187 Visits: 365
yes it does find all the data by itself, if I take the code and ut it into the trigger it works...but I need this trigger to execute a couple of stored procedures
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47239 Visits: 44377
Can you post the stored proc code please? Without seeing that, there's not a chance in hell any of us are going to be able to guess why the trigger 'doesn't work'.


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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


crazy_new
crazy_new
SSC-Enthusiastic
SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)

Group: General Forum Members
Points: 187 Visits: 365
BEGIN
INSERT INTO PAT_AJS.dbo.AJS_Client_Invoices

SELECT IL.INVOICE_ID, IH.Invocie_DATE,
IH.Case_ID,IH.Actor_ID,IL.Invoice_Line_Text ,IL.Invoice_Amount,B_L_SEQ_NUMBER,B_L_AMOUNT,BL.WORK_CODE_ID
FROM INVOICE_LINE IL, INVOICE_HEADER IH, BUDGET_LINE BL
WHERE IH.Invoice_ID = IL.Invoice_ID

AND IL.INVOICE_ID = (SELECT MAX(invoice_id)
FROM INVOICE_HEADER
WHERE INVOICE_ID > 9990000
AND INVOICE_ID LIKE '1%')
AND B_L_INVOICE_NUMBER = IH.INVOICE_ID


END
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search