I tried to avoid using the cursor in this particular case just because I donβt like compromises, and this is how the process that I use happens because the triggers look like the right course of action.
A stored procedure inserts a record based on a complex mix of sentences using an insert trigger. I am sending an email to the target user who tells them to visit the site. It works easily and perfectly.
However, another procedure is to run every night and distribute all unsolicited entries. The way I did this was to make another insert based on the choice in the date field when it was assigned. To wit:
INSERT INTO Table (ID, User, AssignDate, LastActionDate) SELECT ID ,User ,GETDATE() [AssignDate] ,GETDATE() [LastModifiedDate] FROM Table2
The trigger works with individual inserts, but the select statement above only works with the last inserted row. Is there any way around this behavior? It ruins it all!
Edit (startup code):
ALTER TRIGGER dbo.Notify ON dbo.Table AFTER INSERT AS BEGIN DECLARE @EmailSender varchar(50)='Sender Profile' DECLARE @Identity int DECLARE @User varchar(20) DECLARE @Subject varchar(50) SET @ Identity=@ @Identity SELECT @User=User, @Subject='(' + CONVERT(varchar,@Identity) + ')!' FROM Table WHERE idNum=@Identity exec msdb.dbo.sp_send_dbmail @ profile_name=@EmailSender , @ recipients=@User @ subject=@Subject , @body='//etc' END
source share