I have a trigger which needs to update a field into my table only for an INSERT.
My trigger reads thus...
CREATE TRIGGER MyTrigger ON MyTable
FOR INSERT
AS
DECLARE @SerialNo varchar (20)
--Get the 6 char date
SET @SerialNo = CONVERT(char(20), GETDATE(),112)
SET @SerialNo = RIGHT(RTRIM(@SerialNo), 6)
UPDATE MyTable SET MyTable.field = @SerialNo
FROM Inserted
WHERE MyTable.RecID = Inserted.RecID
and len(Inserted.field) = 0
If this was an UPDATE trigger, this code works great, but of course during the INSERT, the table record doesn't exits yet so I can't use
WHERE MyTable.RecID = Inserted.RecID
I need to update the inserted.field, but inserted is a strictly a readonly affair, so how can I update the field as a record is INSERTed?
cheers
My trigger reads thus...
CREATE TRIGGER MyTrigger ON MyTable
FOR INSERT
AS
DECLARE @SerialNo varchar (20)
--Get the 6 char date
SET @SerialNo = CONVERT(char(20), GETDATE(),112)
SET @SerialNo = RIGHT(RTRIM(@SerialNo), 6)
UPDATE MyTable SET MyTable.field = @SerialNo
FROM Inserted
WHERE MyTable.RecID = Inserted.RecID
and len(Inserted.field) = 0
If this was an UPDATE trigger, this code works great, but of course during the INSERT, the table record doesn't exits yet so I can't use
WHERE MyTable.RecID = Inserted.RecID
I need to update the inserted.field, but inserted is a strictly a readonly affair, so how can I update the field as a record is INSERTed?
cheers