Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2014-09-24 : 19:02:09
|
[code]declare @tbl table ( pkid int not null, id int not null, Date1 date not null, Date2 date null, MainNumber int not null )insert into @tbl ( pkid, id, Date1, Date2, MainNumber )values (1, 234, '1/1/2014', NULL, 888888), (4, 234, '2/4/2014', NULL, 777777), (19, 234, '5/6/2014', NULL, 898899), (23, 435, '2/5/2014', NULL, 234532), (56, 435, '8/2/2014', NULL, 234802)/**/select 'Before', * from @tbl;with OrderByDate as (select t.*, row_number() over (partition by id order by Date1 DESC) rnfrom @tbl twhere t.id = 234)update obdset Date2 = '17760704'from OrderByDate obdwhere obd.rn <> 1select 'After', *from @tbl[/code] Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy |
|
|