I started on an ADS sql table trigger to store changes done on one particular table. Here is the idea:
//-------- sql trigger to store changes on patients table to auditLog Table
//----------------------------------------------------------------------
declare cChanges Char( 5000 );
declare allColumns Cursor ;
declare FieldName Char( 25 );
declare StrSql Char( 255 );
declare @new cursor as select * from __new;
declare @old cursor as select * from __old;
open @old;
fetch @old;
open @new;
fetch @new;
Set cChanges = '';
Open AllColumns as Select * from system.columns where parent = 'patients';
while fetch allColumns DO
// Try
FieldName = allColumns.Name;
StrSql = 'IF @new.'+FieldName
+ '<> @old.'+FieldName
+' and @old.'+FieldName + '<> [ ] THEN '
+ 'cChanges = Trim( '+cChanges+' ) + @old.'+FieldName
+ ' Changed to ' + '@new.'+fieldname
+ ' | '+ 'ENDIF ; ' ;
Execute Immediate StrSql ;
// Catch ALL
// End Try;
End While;
if cChanges <> '' THEN
Insert Into AuditLog ( TableKey, Patient, [table], [user], creation, Changes )
values( @new.patient, @new.patient, [Patietns], User(), Now(), cChanges ) ;
ENDIF;
CLOSE AllColumns;
//--------------------------
The above trigger code errors with reporting variable cChanges does not exists.
Can someone help?
Reinaldo.