|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-03-20 : 10:34:00
|
| I have a table sample:DECLARE @Sample TABLE (Merchant VARCHAR(1), OldOrder INT, OrderType VARCHAR(20), NewOrder INT, cdate datetime)INSERT @SampleSELECT 'a', 1, 'new', 1,'1/1/2003' UNION ALLSELECT 'a', 2, 'renewal',2,'8/2/2003' UNION ALLSELECT 'a', 3, 'renewal', 3, '2/1/2004'UNION ALLSELECT 'a', 4, 'renewal', 4,'11/1/2004' UNion ALLSELECT 'a', 5, 'renewal' ,5, '3/8/2006'UNION ALLSELECT 'a', 6, 'new', 1, '3/1/2004' UNION ALLSELECT 'a', 7, 'new', 1,'12/3/2005' UNION ALLSELECT 'a', 8, 'renewal',2, '8/2/2005'UNION ALLSELECT 'a', 9, 'renewal', 3,'9/2/2006'UNION ALLSELECT 'a', 10, 'renewal',4, '10/2/2006'UNION ALLSELECT 'a', 11, 'renewal', 5, '11/2/2006' UNION ALLSELECT 'b', 1, 'new', 1,'8/2/2003'UNION ALLSELECT 'b', 2, 'new', 1,'9/2/2003'UNION ALLSELECT 'b', 3, 'new', 1,'8/2/2005'UNION ALLSELECT 'c', 1, 'new', 1,'8/2/2004'UNION ALLSELECT 'c', 2, 'renewal',2,'8/2/2005' UNION ALLSELECT 'c', 3, 'renewal',3,'9/2/2005' UNION ALLSELECT 'd', 2, 'new',1 ,'8/2/2005'UNION ALLSELECT 'd', 3, 'renewal',2, '4/2/2006'UNION ALLSELECT 'd', 4, 'renewal',3, '6/2/2006'UNION ALLSELECT 'd', 4, 'renewal',4,'9/2/2006'I want to remve all records serials startign with type 'new' (neworder 1) which is later than ,1/1/2005' and subsquncial renewals The desire result should be:Merchant OldOrder OrderType NewOrder cdatea 1 new 1 2003-01-01 00:00:00.000a 2 renewal 2 2003-08-02 00:00:00.000a 3 renewal 3 2004-02-01 00:00:00.000a 4 renewal 4 2004-11-01 00:00:00.000a 5 renewal 5 2006-03-08 00:00:00.000a 6 new 1 2004-03-01 00:00:00.000b 1 new 1 2003-08-02 00:00:00.000b 2 new 1 2003-09-02 00:00:00.000c 1 new 1 2004-08-02 00:00:00.000c 2 renewal 2 2005-08-02 00:00:00.000c 3 renewal 3 2005-09-02 00:00:00.000Thanks.Jeff |
|