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-05 : 07:51:16
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-05 : 08:05:36
You need to investigate the usage of the TOP or SET ROWCOUNT commands.
You'll also need to include an ORDER BY phrase.

SEARCH here for the above keywords....to help yourself.
If you're still stuck....revert
Go to Top of Page
   

- Advertisement -