CaptainN64
Programmer
Hi. I'm using a copy of SQL7 and have this trigger written:
alter trigger u_per_master on per_master
for update
as
begin
declare @counter int
declare @fieldcounter int
declare @fieldname varchar(50)
declare @fieldnumber int
declare @oldvalue varchar(50)
declare @newvalue varchar(50)
set @counter=1
while @counter<=len(columns_updated())
begin
set @fieldcounter=1
while @fieldcounter<9
begin
if substring(columns_updated(),@counter,1) & power(2,@fieldcounter-1)>0
begin
declare @tableID int
set @tableid=(select id from sysobjects where name='per_master')
set @fieldnumber=(@counter-1)*8+@fieldcounter
set @fieldname=(select name from syscolumns where id=@tableid and colid=@fieldnumber)
----------------BEGIN PROBLEM AREA------------------
set @oldvalue=(select @oldvalue from deleted)
set @newvalue=(select @fieldname from inserted)
------------------END PROBLEM AREA------------------
print 'Field "' + @fieldname + '" updated from "'+@oldvalue+'" to "'+@newvalue+'"'
end
set @fieldcounter=@fieldcounter+1
end
set @counter=@counter+1
end
end
... My problem is that I'm trying to select the field name dynamically as I do in VB or any other language, but I'm not sure how to do that... Any help would be appreciated. Thanks!
<aptain/\/64
alter trigger u_per_master on per_master
for update
as
begin
declare @counter int
declare @fieldcounter int
declare @fieldname varchar(50)
declare @fieldnumber int
declare @oldvalue varchar(50)
declare @newvalue varchar(50)
set @counter=1
while @counter<=len(columns_updated())
begin
set @fieldcounter=1
while @fieldcounter<9
begin
if substring(columns_updated(),@counter,1) & power(2,@fieldcounter-1)>0
begin
declare @tableID int
set @tableid=(select id from sysobjects where name='per_master')
set @fieldnumber=(@counter-1)*8+@fieldcounter
set @fieldname=(select name from syscolumns where id=@tableid and colid=@fieldnumber)
----------------BEGIN PROBLEM AREA------------------
set @oldvalue=(select @oldvalue from deleted)
set @newvalue=(select @fieldname from inserted)
------------------END PROBLEM AREA------------------
print 'Field "' + @fieldname + '" updated from "'+@oldvalue+'" to "'+@newvalue+'"'
end
set @fieldcounter=@fieldcounter+1
end
set @counter=@counter+1
end
end
... My problem is that I'm trying to select the field name dynamically as I do in VB or any other language, but I'm not sure how to do that... Any help would be appreciated. Thanks!
<aptain/\/64