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.
Author |
Topic |
brorobo
Starting Member
3 Posts |
Posted - 2012-01-03 : 16:28:44
|
I apologize in advance if this is not a SQL question, but a rather coding question, but I'm not sure how to do what I'm trying to do.I have a single table that has location and contact information for various events. I am trying to output them to a web page running ColdFusionMX, but I would like to keep the events grouped by month. I don't have any aggregate functions, nor does the output call for any. Here's what I have:SELECT event_ID, event_title, event_city, event_state, event_venue, event_startdate, event_startDay, event_startMonth, event_startYear, event_endDate, event_endDay, event_endMonth, event_endYear, event_startTime, event_startTimeHour, event_startTimeMin, event_startTimeMeridian, event_endTime, event_endTimeHour, event_endTimeMin, event_endTimeMeridian, event_comment1, event_contact, event_email, event_phone, event_fax, event_link1FROM Events_Calendar_TESTWHERE event_startTime > DateAdd(d, -1, GetDate())ORDER BY event_startTime, event_title I can output all the events in a list in the proper order, but I'd like to separate the different months. Obviously when I try to change the ORDER BY to a GROUP BY, I get the standard GROUP BY error: "event_ID is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."Any help would be greatly appreciated, even if it's pointing me in the right direction. Thanks in advance. |
|
X002548
Not Just a Number
15586 Posts |
|
brorobo
Starting Member
3 Posts |
Posted - 2012-01-04 : 13:39:25
|
Thanks for the reply.There's nothing wrong with ORDER BY, it's just not displaying the way I would like. I'm trying to lump the events together by month with a header: JANUARY 2012Date (Times)Event 1 (linked)City, State, venuemailto:contact phone, faxinfo Date (Times)Event 2 (linked)City, State, venuemailto:contact phone, faxcomment Date (Times)Event 3 (linked)City, State, venuemailto:contact phone, faxcomment FEBRUARY 2012Date (Times)Event 4 (linked)City, State, venuemailto:contact phone, faxcommentInstead, it's coming out like this:JANUARY 2012Date (Times)Event 1 (linked)City, State, venuemailto:contact phone, faxinfo Date (Times)Event 2 (linked)City, State, venuemailto:contact phone, faxcomment JANUARY 2012Date (Times)Event 3 (linked)City, State, venuemailto:contact phone, faxcomment FEBRUARY 2012Date (Times)Event 4 (linked)City, State, venuemailto:contact phone, faxcommentAgain, I apologize if this is not a SQL question, but a coding question, but I was hoping it could be accomplished either way.quote: Originally posted by X002548 What's wrong with ORDER BY Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
|
 |
|
X002548
Not Just a Number
15586 Posts |
|
brorobo
Starting Member
3 Posts |
Posted - 2012-01-04 : 14:26:08
|
I don't want all the columns in the query, no, but I do want a few. I can clear up the SQL, that's not a problem.The ColdFusion code for the output looks like this:<code><cfoutput query="GetEvents" group="event_startTime"><h2>#dateformat(event_startTime, 'mmmm')#</h2><ul> <cfoutput> <li> #DateFormat(event_startTime, "mmmm d, yyyy")# (#TimeFormat(event_startTime, "hh:mm")#)<br /> <strong> <a href="#event_link1#" target="NKF">#event_title#</a> </strong> <br /> <span class="small"> #event_city#, #event_state# #event_venue# <a href="mailto:#event_email#">#event_contact#</a> #event_phone#, #event_fax# <br /> #Replace(Trim(event_comment1),'#chr(13)#','<br />','all')# </span></li> </cfoutput></ul></cfoutput></code>Also, here are the datatypes for each column:event_ID intevent_title nvarcharevent_city nvarcharevent_state nvarcharevent_venue nvarcharevent_startdate nvarcharevent_startDay nvarcharevent_startMonth nvarcharevent_startYear nvarcharevent_endDate nvarcharevent_endDay nvarcharevent_endMonth nvarcharevent_endYear datetimeevent_startTime nvarcharevent_startTimeHour nvarcharevent_startTimeMin nvarcharevent_startTimeMeridian nvarcharevent_endTime datetimeevent_endTimeHour nvarcharevent_endTimeMin nvarcharevent_endTimeMeridian nvarcharevent_comment1 ntextevent_contact nvarcharevent_email nvarcharevent_phone nvarcharevent_fax nvarcharevent_link1 nvarcharSo to answer your question, the field names are in [brackets] belowJANUARY 2012 [event_startTime mmmm,yyyy]Date (Times) [event_startTime mmmm, dd yyyy] [event_startTime hh:mm]Event 1 (linked) [event_link1] [event_title]City, State, venue [event_city] [event_state] [event_venue]mailto:contact phone, fax [event_email] [event_contact] [event_phone] [event_fax]info [event_comment1]Thanks again for your assistance.quote: Originally posted by X002548 Ah, OK, a tad bit clearer..see you DONT want all the data in your columnsWhere Does THISJANUARY 2012Date (Times)Event 1 (linked)City, State, venuemailto:contact phone, faxinfo Data come from...what columns in your table?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
|
 |
|
|
|
|
|
|