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
 Other Forums
 Other Topics
 Select a variable number of rows.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-03-08 : 08:17:54
Marie writes "I want to select ALL the Visitors for today
(start_date = sysdate), no matter how many there are but I want to set a max number and if today's visitor count is < max, then select some visitors from future dates until we have max number of total visitors.

Do you know of a way to write the query to do this?

select
'Visitor - '|| start_date,
FROM visit_table
WHERE visit_num IN(
SELECT visit_num
FROM visit_table
WHERE (start_date BETWEEN SYSDATE-1 AND SYSDATE+30)
or (end_date between SYSDATE-1 and SYSDATE+30)
or (start_date < SYSDATE-1 and end_date > SYSDATE+30))


Thanks!"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-03-10 : 08:33:10
If you're going to double-post....at least have the decorum not to cut/copy/paste the exact same query!...see the answer already given.....then experiment a bit with something simpler, and finally move on towards solving your problem!


http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=33112
Go to Top of Page
   

- Advertisement -