sql server - Cursor inside Trigger not working -
This simply updates / does not work. When I remove the cursor declaration, it works. The cursor is simply selecting a field from the table that is present in the same database called "Contact" What's wrong?
Use [DDB] GO GO ANSI_NULLS set QUOTED_IDENTIFIER set to be different from Create TRIGGER [dbo]. [Requeststrigger] running [DBO]. [Request] After INSERT, start updating as @ email VARCHAR (400); DECLARE @ First name VARCHAR (400); DECLARE @requestno VARCHAR (400); DECLARE @lastname VARCHAR (400); DECLARE @statusid INT; Select inserted.requestno, contacts.firstname, contacts.lastname, contacts.email request_contacts, contact, inserted where request_contacts.requestid = inserted.requestid and contacts.contactid = request_contacts.contactid and request_contacts.notification = 1 and announced thecursor cursor contacts .notification = 1; SET @statusid = (Selected StatSat); If @Statusad = 4 and @inctused & lt; & Gt; Set the set set on apple set (deleted Szcatsatsat); @ Requestno, @ firstname, @ lastname, @ email while @@ FETCH_STATUS check not bring the next thecursor = 0 start EXEC MAIL_SEND @ email, @ firstname, @ requestno, @ lastname; Before FETCH @ requestno, @firstname, @ last name, stop e-mail, close cursor; Returning Thecursor SET NOCOUNT OFF END END
Are you ready to consider revising its design? There appear a couple of issues with what you are trying to do here.
A trigger is the best place to do this kind of line-by-line operation, because it is not implemented in-line, with changes in the source table, and the system's performance negatively affected Will do
In addition, your current address for a line in batch
There may be a more robust method for inserting rows for which a line table for MAIL_SEND
, one of which can select scheduled job rows and MAIL_SEND can execute
, set a flag so that each operation is done only once.
It's easy to put your trigger - a cursor will not be required (although you'll still need to loop the job of some sort).
Comments
Post a Comment