Hello Sergiy
After some test, i change the script like this:
USE [NMYDATABASE]
GO
/****** Object: Trigger [dbo].[trgAfterINSERT] Script Date: 12/02/2016 10:19:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[trgAfterINSERT] ON [dbo].[fi]
AFTER INSERT
AS
SET NOCOUNT ON;
/* this part for test environment only
--check if any records from inserted match SL
SELECT *
FROM SL sl
RIGHT JOIN inserted i ON i.fistamp = sl.fistamp AND i.fistamp = sl.slstamp
*/
-- perform update here in SL table
UPDATE sl
SET lote = ISNULL(RTRIM(i.lobs2),'')
FROM SL sll
INNER JOIN inserted i ON i.fistamp = sll.fistamp AND i.fistamp = sll.slstamp
GO
EXEC sp_settriggerorder @triggername=N'[dbo].[trgAfterINSERT]', @order=N'Last', @stmttype=N'INSERT'
I think on your original trigger script, the alias that you have mencioned for the table SL had the same name of the table , than i changed to sll.
Also, i write the settriggerorder to fire LAST, because the program manufacturer have by default a trigger for Insert.
Now, everything work OK.
Sorry to answer you just now, but I thought it best to first make some tests to rule out the problem.
I will also thanks for the explanation about the question of using the variables.
Just a curiousity about your script, if i uncomment :
--check if any records from inserted match SL
SELECT *
FROM SL sl
RIGHT JOIN inserted i ON i.fistamp = sl.fistamp AND i.fistamp = sl.slstamp
sql server return this error when i hit F5 on QA:
Msg 311, Level 16, State 1, Procedure trgAfterINSERT, Line 29
Cannot use text, ntext, or image columns in the 'inserted' and 'deleted' tables.
How avoid this error, because this tecnique could be useful.
Many thanks for your great help.
Best regards,
Luis