Hi,
As a user with little or no experience i have to create a trigger on a table (or find another solution). What needs to be accomplished is that when the value of the column ESB is changed to '1' in another row in the table the column has to be set to '0'.
My intention was to use a AFTER UPDATE trigger, to do this.
ALTER TRIGGER [TR_PHOTO_UPD]
ON [SOA].[dbo].[photos_TEST]
AFTER UPDATE
AS
DECLARE @ID VARCHAR(10)
DECLARE @ESB VARCHAR(1)
SELECT @ID = (SELECT TOP(1) ID
FROM SOA.dbo.photos_TEST
WHERE esb = 'Q'
ORDER BY ARRIVALDATETIME ASC)
SELECT @ESB (SELECT esb FROM INSERTED)
IF @ESB = '1'
UPDATE SOA.dbo.photos_TEST SET esb = '0' WHERE ID = @I
This as, you probably understand, does not work, neither the next trigger definition.
ALTER TRIGGER [TR_PHOTO_UPD]
ON [SOA].[dbo].[photos_TEST]
AFTER UPDATE
AS
DECLARE @ID VARCHAR(10)
DECLARE @ESB VARCHAR(1)
SELECT @ID = (SELECT TOP(1) ID
FROM SOA.dbo.photos_TEST
WHERE esb = 'Q'
ORDER BY ARRIVALDATETIME ASC)
SELECT @ESB (SELECT esb FROM INSERTED)
IF @ESB = '1'
BEGIN
UPDATE SOA.dbo.photos_TEST
SET esb = '0'
WHERE id = (SELECT TOP(1) ID
FROM SOA.dbo.photos_TEST
WHERE esb = 'Q'
ORDER BY ARRIVALDATETIME ASC)
END
After several hours of googling and trying i have not yet found out why the row is not updated to '0'. I have a suspicion that the UPDATE in an AFTER UPDATE trigger is the reason why it does not work. Has somebody any hints or better a solution ?
Cheers,
Peter