create table table1(name varchar(10),date smalldatetime,dj numeric(10,2))
insert table1 select 'A','2007-1-1',20.56
union all select 'A','2007-1-1',21
union all select 'A','2007-2-1',21
union all select 'A','2007-2-1',20
update b set b.dj=a.dj from (select top 1 * from table1 a
where not exists(select 1 from table1 where a.name=name and a.date<date)
order by newid()) a ,table2 b
where a.name=b.name
update b set b.dj=a.dj from (select top 1 * from table1 a
where not exists(select 1 from table1 a.name=name and a.date<date)
order by newid()) a ,table2 b
where a.name=b.name
declare @a table(name varchar(10),date smalldatetime,dj numeric(10,2))
insert @a select 'A','2007-1-1',20.56
union all select 'A','2007-1-1',21
union all select 'A','2007-2-1',21
union all select 'A','2007-2-1',20
insert T select 'A','2007-07-02',23
union all
select 'B','2007-07-02',233
create table TT(id varchar(10),dt datetime,fs int)
insert TT select 'A','2007-07-02',23
union all
select 'A','2007-07-02',233
union all
select 'A','2007-07-02',21
union all
select 'A','2007-07-02',22
update a set a.fs=(select max(fs) from TT t where t.id=a.id ) from T as a,TT as aa where a.id=aa.id
update t2
set dj = t.dj
from t1,
(
select name, max(dj) dj
from t1 a
where not exists (select 1 from t1 where date > a.date)
group by name
) t
where t1.name = t.name
---------------------------
select * from t1
drop table t1, t2
declare @a table(name varchar(10),date smalldatetime,dj numeric(10,2))
insert @a select 'A','2007-1-1',20.56
union all select 'A','2007-1-1',21
union all select 'A','2007-2-1',21
union all select 'A','2007-2-1',20
update s set
dj=(select top 1 dj from @a where name=gg.name and [date]=gg.[date]) from @b s
left join (select name,max([date]) [date] from @a group by name) gg
on s.name=gg.name