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)
 I can't even fathom where to start this.

Author  Topic 

Blastrix
Posting Yak Master

208 Posts

Posted - 2001-05-23 : 22:23:08
Okay, I have been pondering how to write this query all day. but I just can't seem to get it. Here's what I need to return:

newsId int,
postTime dateTime,
title varchar(100)

I'm looking to return up to five days previous news listings. Each day can have unlimited listings. And there isn't necessarily a news listing for every day. So there could be news on the 23, 22, 19, 18, 17, 16, etc...

How could I write the query to return the records retrieve 5 prior days? SELECTing TOP anything won't work, since there can be any number per day, and SELECTing the records WHERE the date is greater than the current date - 5 won't work since there can be gaps. What do you guys recommend for going about this?

   

- Advertisement -