hai
Yak Posting Veteran
84 Posts |
Posted - 2009-04-07 : 10:42:39
|
I need to run a query to updated the field values based on the audit values. Here are the sample below...this is working fine, except it is a bit slow. Any suggestion on how to re-write this stuffs.thanks------------------------DECLARE @t TABLE( id INT,audit_date DATETIME,audit_action CHAR(1),audit_groupid INT,audit_values_old VARCHAR(100),audit_values_new VARCHAR(100) )INSERT INTO @t (id,audit_date,audit_action,audit_groupid,audit_values_old)SELECT 1,'01/21/09','U',68,' TRUST - SUB ACCOU'UNION ALLSELECT 2,'04/03/09','U',68,' TRUST - SUB ACCOUNT 'UNION ALLSELECT 3,'01/21/09','U',268,'TRUST MID ACCT'UNION ALLSELECT 4,'04/03/09','U',268,'TRUST MID CAP ACCT 'UNION ALLSELECT 5,'10/30/08','D',440,'RIQUEZ 'UNION ALLSELECT 6,'04/03/09','U',440,'ADCHAM'UNION ALLSELECT 7,'10/30/08','U',441,'SLAK'UNION ALLSELECT 8,'01/22/09','U',441,'SASSO'UNION ALLSELECT 9,'12/02/08','U',442,' 'UNION ALLSELECT 10,'12/23/08','U',442,'FRANK'UNION ALLSELECT 11,'12/23/08','U',442,'FRANK JR'UNION ALLSELECT 12,'01/22/09','U',442,'FRANK JR III'SELECT * FROM @tdeclare @id intdeclare @id2 intset @id=1set @id2=(select max(id) from @t)while @id <= @id2 begin update T set audit_values_new = (Select audit_values_old from @t X where X.id = @id+1) from @t T where T.id=@id and t.audit_groupid=(Select audit_groupid from @t X where X.id = @id+1) set @id=@id+1 endSELECT * FROM @t2 |
|