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 2005 Forums
 Transact-SQL (2005)
 Events table - Group by Date/Order by Time

Author  Topic 

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2010-05-25 : 06:38:11
Hello,

I am having trouble creating a statement that can group my events by date and order the time of the events on that date. Basically, I have a conference that over a couple of days. With in these days there are several events at given times. I would like to create a query that can get all events for each day of the conference. Here is what I have so far:


SELECT
title, starttime, endtime, date, description
FROM conference_events
where conferenceID = 1 and active = 1
group by date
order by startime


Both date and starttime are "datetime" fields. Thanks in advanced for helping

Sachin.Nand

2937 Posts

Posted - 2010-05-25 : 07:38:00
I dont think above query will work as lot of group by columns are missing.
Whats your table structure and data?Please post some sample data and output.

PBUH
Go to Top of Page

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2010-05-25 : 08:07:06
Ok I went ahead and create a join table to normalize this data more.

The join table has the conferenceid, eventid, and the event date. Do you think it would be possible to use a group by date and order by time on this query?
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-05-25 : 08:09:53
I dont think that wont help either.You need to post some sort of sample data.Have a look here on how to do it.
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

PBUH
Go to Top of Page

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2010-05-25 : 08:10:22
Like this?


select e.title, e.starttime, e.date
from conference_events e

inner join conference_event_join ce on e.id = ce.eventid

group by ce.date
order by e.date asc,e.starttime
Go to Top of Page
   

- Advertisement -