|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2004-01-05 : 09:43:01
|
| Say you have the following table :[CODE]CREATE TABLE ALLMEMBERS (PERSONKEY INT,MEMBERKEY INT,SURNAME VARCHAR(30),MEMBERSTATUS VARCHAR(2),LASTUPDATE DATETIME,DUPFLAG SMALLINT,CREATEFLAG SMALLINT) ON [PRIMARY]GOINSERT INTO ALLMEMBERS (PERSONKEY, MEMBERKEY, SURNAME, MEMBERSTATUS, LASTUPDATE, DUPFLAG, CREATEFLAG)SELECT 370, 10590, 'LAWRENCE', 'A', '1942-08-14', 0, 0 UNION ALLSELECT 371, 10590, 'LAWRENCE', 'A', '1942-08-14', 0, 0 UNION ALLSELECT 472, 10713, 'CROMBIE', 'AC', '2003-10-13', 0, 0 UNION ALLSELECT 473, 10713, 'CROMBIE', 'PP', '2003-08-15', 0, 0 UNION ALLSELECT 473, 10713, 'CROMBIE', 'PP', '2003-08-15', 0, 0[/CODE]The problem is one of isolating duplicate records and picking the correct one to populate from. For each duplicate MEMBERKEY, the record with the latest LASTUPDATE date is the one I want to mark. Where this is the same for both, I would choose by STATUS, or if these are also identical, the first record found. When the latest record is found I then want to set the CREATEFLAG to 1.Any ideas how to do this in a simple update statment?________________Make love not war! |
|