Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic field name in UPDATE trigger

Status
Not open for further replies.

CaptainN64

Programmer
Oct 23, 2002
9
US
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 &quot;' + @fieldname + '&quot; updated from &quot;'+@oldvalue+'&quot; to &quot;'+@newvalue+'&quot;'
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top