Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 populate another table using max date

Author  Topic 

sachingovekar
Posting Yak Master

101 Posts

Posted - 2010-11-23 : 00:36:43
Hi ,

want to populate #info table using max date.

create table #master (
product varchar(100),
dateadded datetime,
parent varchar(100))

insert into #master values('apple','2010-11-14 12:40:00.000','lime')
insert into #master values('apple','2010-11-13 12:34:00.000','orange')
insert into #master values('apple','2010-05-26 17:25:00.000','guava')

create table #info
( product varchar(100),
dateadded datetime,
parent varchar(100))

insert into #info values ('apple','','')

OUTPUT REQUIRED:
APPLE 2010-11-14 12:40:00.000 LIME

Regards,
Sachin

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-11-23 : 00:45:37
select m.*
from
#master m join
(select product ,max(dateadded) as maxdate from #master group by product)m1 on m.dateadded =m1.maxdate and m.product=m1.product
Go to Top of Page

sachingovekar
Posting Yak Master

101 Posts

Posted - 2010-11-23 : 01:11:54
if I add this into #master
insert into #master values('pineaaple','2010-05-26 17:25:00.000','guava')
the query goes wrong
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-26 : 10:13:28
What si your expected result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -