Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Avatar
Starting Member
2 Posts |
Posted - 2004-05-27 : 11:17:30
|
hi folks.Í want to do this:/***************************************/CREATE TRIGGER TRGfechaModificacionON UsuariosVencimientosAFTER UPDATE ASDECLARE @updatedID AS intBEGIN--Get the last ID updatedSELECT @updatedID = @@updated --???-- Updated this record with the actual datetimeUPDATE UsuariosVencimientos SET Fecha_Actualizacion = getDate()WHEREid = @updatedID END/***************************************/Resume:I want to get the 'id' updated so I can used for the update query<b>Greetings</b>------------------- |
|
|
mtomeo
Starting Member
30 Posts |
Posted - 2004-05-27 : 12:13:00
|
| ASSuming updateID is an identity column, grab the value of @@Identity after your Insert:INSERT INTO UsuariosVencimientos (....)VALUES (....)SELECT @@IDENTITY AS 'updateID'A trigger would be overkill if it's an Identity column. If it's not an Identity column and the data from the Insert isn't available to you (IE the insert is generated from differenct applications or whatnot), just grab the value of updateID from the "inserted" table (Do a search on "CREATE TRIGGER" in BOL for more help). |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-05-27 : 12:49:52
|
When you work with triggers, you always need to keep in mind that the trigger fires once per DML, not once per row.CREATE TRIGGER TRGfechaModificacionON UsuariosVencimientosAFTER UPDATE ASbeginupdate uvset Fecha_Actualizacion = getDate()from UsuariosVencimientos uv inner join inserted i on uv.id = i.id -- (Assuming id is your PK)end Jay White{0} |
 |
|
|
Avatar
Starting Member
2 Posts |
Posted - 2004-05-27 : 16:31:36
|
Thank you all.Your solutions works fine ;)Greetings------------------- |
 |
|
|
|
|
|