Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UPDATE() in triggers
Message
From
22/10/2003 12:02:44
 
 
To
22/10/2003 11:02:18
Jenny Karlsson
Megasol Technologies
Uppsala, Sweden
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00841063
Message ID:
00841111
Views:
27
The Inserted table will contain all of the rows that were modified. You don't need a cursor:

IF UPDATED(amount)
UPDATE table1 SET ... WHERE pk IN (SELECT pk FROM Inserted)

-Mike

>I would like to update all rows in table1 where the column amount
>had been updated, if column amount hasn't been updated go to next row.
>I would like to do this check UPDATE(amount) for each row in cursor. I think this code loop through all posts in inserted and not only the ones where amount had been updated. Can anybody give me a solution for this problem?
>
>
>CREATE TRIGGER tr_Name
>ON dbo.table1
>FOR INSERT, UPDATE
>AS
>
>IF UPDATE(amount)
>BEGIN
>        DECLARE curInserted INSENSITIVE CURSOR FOR
>		SELECT date, idnr, amount
>		FROM inserted
>		ORDER BY date
>
>	OPEN curInserted
>	FETCH NEXT FROM curInserted
>	INTO @ldDate, @lcIdNr, @lnAmount
>
>	WHILE @@FETCH_STATUS = 0
>	BEGIN
>		....code...
>	
>		FETCH NEXT FROM curInserted
>		INTO @ldDate, @lcIdNR
>	END
>END
>
>
>
>
>Regards Jenny
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform