returning results in rows

K

Ken

I have a db with the fields Day, Month, Year and Message. How can I select
all of the messages for the current week starting with sunday and return the
results as a list?

Thanks
Ken
 
R

Ray at

By using a SELECT query. What part are you stuck on? How far have you
gotten so far?

Ray at work
 
A

Aaron Bertrand - MVP

What kind of database are you using???

Why did you separate day, month and year? It's fine if your date ranges
never cross month or year boundaries, but you're going to have a hard time
querying a range like 2003-12-26 -> 2004-01-03.

Bad column name choices too, by the way. Three of your four columns are
reserved words.

Anyway. You can't reliably get a list from a set of columns, as this
violates set theory. (Databases are used to store sets of data. If you are
not storing sets, but rather lists, just use a flat file.) Granted, there
are ways to do it, but this is better handled in the application.

First, you have to figure out when Sunday was, then return a set of ROWS
that fall in that category.

sunday = dateadd("d", 1-datepart("w", date()), date())
sunday = year(sunday) & "-" & month(sunday) & "-" & day(sunday)
sql = "SELECT [day], [month], [year], message FROM sometable WHERE CDate("'"
& [year] & "-" & [month] & "-" [day] & "'") >= CDate('" & sunday & "')"
set rs = conn.execute(sql)

Then, use ASP to translate the rows into a list,

thislist = ""
prevday = -1
do while not rs.eof
if rs(0) <> prevday then
response.write thislist & "<p>"
prevday = rs(0)
response.write rs(2) & "-" & rs(1) & "-" & rs(0) & ":"
thislist = rs(3)
else
thislist = thislist & ", " & rs(3)
end if
rs.movenext
loop
response.write thislist & "<p>"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top