What happens if the column is, and remains, NULL? Or if it's being updated from NULL to a value? Many addresses won't have an address2/3, and that could be null in both the inserted and deleted tables. Or it could be changed from NULL to a value due to running the address through an address verification routine for getting cheaper mailing rates (CASS).
Another potential issue: do you want the date updated if the case of the field is changed, and that's the only change? To handle this, you'll need to deal with case sensitive collations.
Here's an example that shows the NULL issue. Just use the remarked out lines in the trigger to handle them being updated.
SET NOCOUNT ON;
if OBJECT_ID('dbo.Test') IS NOT NULL DROP TABLE dbo.Test;
GO
CREATE TABLE dbo.Test (
RowID int PRIMARY KEY CLUSTERED,
Address1 varchar(50) NULL,
Address2 varchar(50) NULL,
Address3 varchar(50) NULL,
Address1Date datetime NULL,
Address2Date datetime NULL,
Address3Date datetime NULL);
GO
CREATE TRIGGER TestDates
ON dbo.Test
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE dbo.Test
SET Address1Date = GetDate()
FROM dbo.Test
JOIN inserted i
ON i.RowID = Test.RowID
JOIN deleted d
ON d.RowID = Test.RowID
WHERE i.Address1 <> d.Address1
-- OR (d.Address1 IS NULL AND i.Address1 IS NOT NULL);
UPDATE dbo.Test
SET Address2Date = GetDate()
FROM dbo.Test
JOIN inserted i
ON i.RowID = Test.RowID
JOIN deleted d
ON d.RowID = Test.RowID
WHERE i.Address2 <> d.Address2
-- OR (d.Address2 IS NULL AND i.Address2 IS NOT NULL);
UPDATE dbo.Test
SET Address3Date = GetDate()
FROM dbo.Test
JOIN inserted i
ON i.RowID = Test.RowID
JOIN deleted d
ON d.RowID = Test.RowID
WHERE i.Address3 <> d.Address3
-- OR (d.Address3 IS NULL AND i.Address3 IS NOT NULL);
END;
GO
INSERT INTO dbo.Test
SELECT 1, 'TEST ADDRESS 1', NULL, NULL, NULL, NULL, NULL UNION ALL
SELECT 2, 'Test Address 2', 'Test2', NULL, NULL, NULL, NULL UNION ALL
SELECT 3, 'Test Address 3', 'Test3', 'Test3', NULL, NULL, NULL;
-- show updating case doesn't put dates into the table
SELECT * FROM dbo.Test;
UPDATE dbo.Test
SET Address1 = UPPER(Address1),
Address2 = UPPER(Address2),
Address3 = UPPER(Address3);
SELECT * FROM dbo.Test;
-- show effect of updating a field from NULL to a value
UPDATE dbo.Test
SET Address3 = 'MyTest'
WHERE Address3 IS NULL;
SELECT * FROM dbo.Test;
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes