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
 General SQL Server Forums
 New to SQL Server Programming
 Order by Date, LIMIT and OFFSET SQL Pagination Pro

Author  Topic 

rvegas
Starting Member

1 Post

Posted - 2009-09-14 : 01:28:22
Hi all,
I'm not sure if this is possible to do; but if it is I will really appreciate any help.

I have a table like this :
ID DATE TYPE
1 2009-11-23 21:00:00 2
2 2009-06-05 21:00:00 1
3 2009-07-31 21:00:00 0
4 2008-04-20 01:00:00 0
5 2009-04-21 01:00:00 0
6 2009-04-18 21:00:00 3
7 2008-04-19 21:00:00 0
8 2009-06-04 21:00:00 7
...

All these are event dates.
Type 0 are events that only occur 1 time (one time events), all other are recurring event (weekly events), where the date is the first occurrence of the event and the type is the day of the week where they occur (1=mon, 2= tue, etc)

Question:
How can I create a Select query that returns the 10 upcoming events Including one time events and recurring events?
Would I be able to use OFFSET 10 to then get the following 10 events?

Thanks!

ams006
Yak Posting Veteran

55 Posts

Posted - 2009-09-14 : 10:30:40
Try this,

select
top 10 *
from
{tablename}
order by {datefield} desc

Regards

ams006
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-14 : 11:01:13
are you using sql server? limit is not available in sql server. you need to use top instead. also you should order by date asc if you're looking for first 10 upcoming events
Go to Top of Page
   

- Advertisement -