October 23, 2014 at 5:52 pm
Hello
I need help on my trigger because they run always the first Update statment when i update field @Subconta on the beginning of my trigger construction.
this is part of my script:
IF (RTRIM(@SUBCONTA) = '' OR RTRIM(@SUBCONTA) <> '')
AND @ORIGEM = 'FO'
BEGIN
-- Subconta
SELECT @SUBCONTA = CAST(FO.NO AS VARCHAR) from FO WHERE FO.FOstamp = @oristamp
UPDATE ML SET U_SUBCONTA = @SUBCONTA
WHERE MLSTAMP=@STAMP
--Recapit.
SELECT @RECAPVAL = TOTAL , @ERECAPVAL = ETOTAL, @RECAPIT = 'F',@EIVAIN = EIVAIN, @IVAIN = IVAIN ,
@PAIS = PAIS FROM FO WHERE FO.FOSTAMP = @ORISTAMP
--PRINT 'PAIS' + CAST(@PAIS AS VARCHAR)
IF @PAIS = 1 --Here don´t respect the value of @pais, because for @PAIS = 2 the trigger must fire the other update
BEGIN
UPDATE ML SET RECAPIT = @RECAPIT,
RECAPVAL = (Case when @ECRE <> 0 THEN @RECAPVAL ELSE -@RECAPVAL END),
ERECAPVAL = (CASE WHEN @ECRE <> 0 THEN @ERECAPVAL ELSE -@ERECAPVAL END)
FROM ML WHERE MLSTAMP = @STAMP AND ML.CONTA LIKE '22%'
END
ELSE
BEGIN
UPDATE ML SET RECAPIT = @RECAPIT,
RECAPVAL = (Case when @ECRE <> 0 THEN @IVAIN ELSE -@IVAIN END),
ERECAPVAL = (CASE WHEN @ECRE <> 0 THEN @EIVAIN ELSE -@EIVAIN END)
FROM ML WHERE MLSTAMP = @STAMP AND ML.CONTA LIKE '22%'
END
END
Also, for Debug how can fire the PRINT 'PAIS' + CAST(@PAIS AS VARCHAR) that was comment.
Just make na Update to my table ML ??
Many thanks
Luis Santos
October 23, 2014 at 8:02 pm
Please post the entire trigger code, the table schema, sample table data, the update(s) you fire and the expected action by the trigger.
NOTE: I get VERY twitchy when I see variables like that in triggers. It is very likely that your trigger can only process one row, and that is something I have seen a client go out of business for (despite the fact that I TOLD them they were going to go out of business)!!
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply