How about this
create trigger foo on blah
for update
as
if updated (email)
insert into audittable (oldemail, newemail)
select d.email, a.email from contacts a join deleted d on
a.contactid = d.contactid where a.contactemail != d.contactemail
or even better, capture who and when this occurred
create trigger foo on blah
for update
as
if updated (email)
insert into audittable (oldemail, newemail,baduser,occurencedate)
select d.email, a.email,suser_sname(),current_timestamp from contacts a join
deleted d on
a.contactid = d.contactid where a.contactemail != d.contactemail
Think that will do what you need, you might throw a trigger on your
audittable to send an email to the appropriate authorities using xp_sendmail
HTH
--
Ray Higdon MCSE, MCDBA, CCNA
---
[quoted text, click to view] "LittleJonny" <jonaanderson@sbcglobal.net> wrote in message
news:027401c39992$5bf36aa0$a301280a@phx.gbl...
> What am I missing here?
>
> Declare @OldValue varchar(50), @FieldName varchar(50)
> select @FieldName = 'email'
> Select @OldValue = (Select @FieldName from Contacts where
> contactid = 32)
> print @OldValue
>
>
> OldValue always returs as "email" instead
> of "emaaddress@somwhere.com"
>
> I am writing a table audit trigger. Does this sound right?
>
> Get the columns of the tables from the information schema.
> Loop through the columns and use Columns_updated()
> resultst to see if column has been changed.
>
> Use the @ColumnName to get the old and new from deleted
> and inserted (this is where the above problem comes in).
>
> Stick the information in the Audit Table and alert the
> proper authorities.
>
> Thanks
> Jon