bob
3/23/2007 11:39:00 AM
This works:
USE tempdb
GO
DROP TABLE table1
GO
CREATE TABLE table1 ( id INT PRIMARY KEY, column1 VARCHAR(5), column2
VARCHAR(5) )
GO
CREATE TRIGGER trigger1
ON table1
FOR UPDATE
AS
BEGIN
IF UPDATE(column1)
BEGIN
UPDATE t
SET t.column2 = 'value'
FROM table1 t
INNER JOIN inserted u ON t.id =u.id
WHERE t.column1 = '100'
END
END
GO
INSERT INTO table1 SELECT 1, '99', 0
INSERT INTO table1 SELECT 2, '99', 0
SELECT *
FROM table1
UPDATE table1 SET column1 = '100'
WHERE id = 1
SELECT *
FROM table1
Let me know how you get on.
wBob
"CipherTeKST" wrote:
> I am trying to create a trigger that will update a second column once a first
> column is updated in the same row. For example I have a table with several
> columns, I need for the trigger to check column1 to see if the integer has
> reached 100 if so then update column2 in the same record. What I have so far
> is...
> CREATE TRIGGER trigger1
> ON table1
> FOR UPDATE
> AS
> BEGIN
> IF UPDATE(colum1)
> SELECT
> i.colum1
> FROM inserted i
> IF i.column1 = '100'
> UPDATE table1
> SET column2 = 'value'
> END
>
> I'm not sure if this is how the syntax is supposed to look, I keep getting a
> message saying error in syntax near '100'. Please... any help will be GREATLY
> APPRECIATED.
> Thanks.
> --
> CipherTeKST
> MCSE: Security 2003, CCNA, Security+