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)
 Help with Query

Author  Topic 

Karl
Starting Member

8 Posts

Posted - 2002-09-23 : 12:27:26
I am trying to write a statement that will return the records which have a date older than a specified date from a group of records (ie. the most current record (advi_date) in the group is more than 30 days old).

The database is fairly simple. It consists of the following;

dbs_id(int), dest_id(int), cate_id(int), advi_text(ntext), advi_date(datetime)

A unique group would be identified by the same dbs_id and dest_id.

Any help with this would be greatly appreciated.

Thanks ... Karl

nr
SQLTeam MVY

12543 Posts

Posted - 2002-09-23 : 12:42:41
Do you want all the records from the group?

select *
from tbl t1
where exists
(select * from tbl t2 where t1.dbs_id = t2.dbs_id and t1.dest_id = t2.dest_id and t2.advi_date > convert(varchar(8),dateadd(dd,-30,getdate()),112)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Karl
Starting Member

8 Posts

Posted - 2002-09-23 : 14:32:30
Actually, I was only wanting to get one record in the group. The one with the most current date.

I appreciate your help.

Karl

Go to Top of Page
   

- Advertisement -