Click to See Complete Forum and Search --> : TO_CHAR Problem


marleeffh
06-08-2006, 01:30 PM
I am attempting to use a SQL/ASP combo to list all the events in a table, grouped by date, and have them headed by just the month and year, this is my code:

<%
rs.open "SELECT distinct TO_CHAR(eventDate,'MONTH yyyy') AS eventMonth FROM web_events",cn,1,3
if not rs.eof then
do while not rs.eof
eventMonth=rs("eventMonth")
response.write("<h2 class='b'>" & eventMonth & "</h2>")
rs1.open "SELECT * FROM web_events WHERE TO_CHAR(eventDate,'MONTH yyyy')="&eventMonth,cn,1,3
if not rs1.eof then
response.write("<table style='margin:-15px 0 30px 0;'>")
do while not rs1.eof
response.write("<tr><td><h5>" & FormatDateTime(rs1("eventDate"), vbLongDate) & " - " & rs1("eventTitle") & "</h5></td></tr>")
response.write("<tr><td class='list'>" & "rs1('eventTime')" & " &bull; " & "rs1('eventVenue')" & " &bull; " & "rs1('eventCity')" & ", " & "rs1('eventState')" & "</td></tr>")
response.write("<tr><td class='list'>" & Left(rs1("eventBody"),255) & " <a href='event_det.asp?eid=" & rs1("eventID") & "'>" & "more..." & "</a></td></tr>")
rs1.movenext
loop
response.write("</table>")
end if
rs1.close
rs.movenext
loop
end if
rs.close
%>

I'm sure it's not the most elegant way to do it but I'm not generally a programmer. The error I'm getting is on this line

rs1.open "SELECT * FROM web_events WHERE TO_CHAR(eventDate,'MONTH yyyy')="&eventMonth,cn,1,3

the error is "SQL command not properly ended"

I've tried a whole bunch of troubleshooting but can't seem to make any sense of it

thanks for any help!

NogDog
06-08-2006, 08:38 PM
I'm going to move this to the ASP forums in hopes that a guru there can help you. (I think you need some quotes to surround the '&eventMonth' value, but I'm not sure how ASP handles variable names in quotes or concatenates them to a string.

marleeffh
06-08-2006, 11:08 PM
actually i posted it in both places already cuz I wasn't sure where it would fit better, and it was a quote problem, someone on the asp forum helped me earlier, thanks so much though!