473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Query past events of 2007

Hi there,

I have a registration form where I like to filter out the past events of 2007. This is the code I am using :

strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd, EventTimeBegin, Category FROM Events WHERE EventDateBegin >'01/01/2008' AND Events.Category LIKE '3' OR Events.Category LIKE '4' OR Events.Category LIKE '5' OR Events.Category LIKE '6' OR Events.Category LIKE '7' OR Events.Category LIKE '8' OR Events.Category LIKE '9' OR Events.Category LIKE '10' OR Events.Category LIKE '11' OR Events.Category LIKE '12' OR Events.Category LIKE '13' OR Events.Category LIKE '14' OR Events.Category LIKE '15' OR Events.Category LIKE '16' OR Events.Category LIKE '17' OR Events.Category LIKE '18' OR Events.Category LIKE '19' OR Events.Category LIKE '20' OR Events.Category LIKE '21' ORDER BY EventName"

The query I used is "EventDateBegin >'01/01/2008'" but it is not working at all.

The code I am using in the drop-down menu:
<option value="<%=rs("EventName")%> - <%=rs("EventDateBegin")%>"><%=rs("EventName")%> - Date: <%=rs("EventDateBegin")%>

Can anybody advice if I am doing the right way?
Jan 4 '08 #1
14 2181
jhardman
3,406 Expert 2GB
The date should be enclosed in pound signs:
Expand|Select|Wrap|Line Numbers
  1. EventDateBegin >#01/01/2008#
Let me know if this helps.

Jared
Jan 5 '08 #2
Nicodemas
164 Expert 100+
It really depends on the type of database you are using.

MS Access uses octothorpe's (#) to delimit dates; MS SQL Server uses apostrophes. Also, date format is also important.

What isn't working, exactly? Are events from 2007 still showing up,or is the query failing all together?
Jan 6 '08 #3
It really depends on the type of database you are using.

MS Access uses octothorpe's (#) to delimit dates; MS SQL Server uses apostrophes. Also, date format is also important.

What isn't working, exactly? Are events from 2007 still showing up,or is the query failing all together?
Hi guys, thank you for getting back to me.

I am using MSSQL, thus apostrophes is using here. It is not working such that all events from 2007 are still showing up. I would think it is something to do with date format, but I have no idea how to proceed on and resolve from there.
Jan 7 '08 #4
Hi there, any help? :)
Jan 8 '08 #5
jhardman
3,406 Expert 2GB
Hi there, any help? :)
I could have sworn that the octothorpes (that's the first time I've used that word) were the SQL convention for designating dates. It sounds like Nicodemas uses them more than I so he is likely right, but I am still going to suggest it. The apostrophes are definitely used to designate strings in SQL, and I'm surprised (but not astounded) to hear that they would be used for other data types. Let me know if you decide to try it.

Jared
Jan 8 '08 #6
I could have sworn that the octothorpes (that's the first time I've used that word) were the SQL convention for designating dates. It sounds like Nicodemas uses them more than I so he is likely right, but I am still going to suggest it. The apostrophes are definitely used to designate strings in SQL, and I'm surprised (but not astounded) to hear that they would be used for other data types. Let me know if you decide to try it.

Jared
Hi Jared,

Thank you for helping me with this problem. I had tried and this is the error I am getting:

Microsoft OLE DB Provider for SQL Server error '80040e14'
Line 1: Incorrect syntax near '#'.
/Form/index.asp, line 38

:)
Jan 8 '08 #7
jhardman
3,406 Expert 2GB
Hi Jared,

Thank you for helping me with this problem. I had tried and this is the error I am getting:

Microsoft OLE DB Provider for SQL Server error '80040e14'
Line 1: Incorrect syntax near '#'.
/Form/index.asp, line 38

:)
but with ' ' you get get no error, and the where clause is basically ignored? Give me a few minutes, I have a db with a date field in SQL server. I'm just sorting by date, but I can put up a where clause test in 5 minutes.

Jared
Jan 8 '08 #8
jhardman
3,406 Expert 2GB
but with ' ' you get get no error, and the where clause is basically ignored? Give me a few minutes, I have a db with a date field in SQL server. I'm just sorting by date, but I can put up a where clause test in 5 minutes.

Jared
OK, Nicodemas is definitely right. I guess I should learn to trust him. I got it to work just fine. I don't use parentheses in my query, but I would be surprised if that affects anything. Here is my query:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [works] WHERE [date-posted] > '11/1/2007' 
Attached Images
File Type: gif screen1.gif (18.8 KB, 188 views)
Jan 8 '08 #9
jhardman
3,406 Expert 2GB
Oh, duh! The problem is all the "OR"s This is interpreted as only having a date restriction on the first section (when category like '3'), the other categories have no date restrictions. To keep this same format, you would need to write
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd, EventTimeBegin, Category FROM Events WHERE EventDateBegin >'01/01/2008' AND Events.Category LIKE '3' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '4' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '5' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '6' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '7' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '8' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '9' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '10' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '11' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '12' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '13' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '14' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '15' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '16' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '17' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '18' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '19' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '20' OR EventDateBegin >'01/01/2008' AND Events.Category LIKE '21' ORDER BY EventName" 
This would definitely work, but it is extremely unwieldy. Tell me more about the Category field and I might be able to suggest a better way to write this.

Jared
Jan 8 '08 #10
jhardman
3,406 Expert 2GB
OK, Nicodemas is definitely right. I guess I should learn to trust him. I got it to work just fine. I don't use parentheses in my query, but I would be surprised if that affects anything. Here is my query:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [works] WHERE [date-posted] > '11/1/2007' 
I don't know why I was thinking you used parentheses, but maybe they would help. I don't consider myself a SQL expert, but I might be able to write this better.

Jared
Jan 8 '08 #11
jhardman
3,406 Expert 2GB
OK, I looked it up, adding parentheses like this clears it up:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd, EventTimeBegin, Category FROM Events WHERE EventDateBegin >'01/01/2008' AND (Events.Category LIKE '3' OR Events.Category LIKE '4' OR Events.Category LIKE '5' OR Events.Category LIKE '6' OR Events.Category LIKE '7' OR Events.Category LIKE '8' OR Events.Category LIKE '9' OR Events.Category LIKE '10' OR Events.Category LIKE '11' OR Events.Category LIKE '12' OR Events.Category LIKE '13' OR Events.Category LIKE '14' OR Events.Category LIKE '15' OR Events.Category LIKE '16' OR Events.Category LIKE '17' OR Events.Category LIKE '18' OR Events.Category LIKE '19' OR Events.Category LIKE '20' OR Events.Category LIKE '21' ORDER BY EventName)" 
However if Category isn't a text field it could be simplified much more.

Jared
Jan 8 '08 #12
OK, I looked it up, adding parentheses like this clears it up:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd, EventTimeBegin, Category FROM Events WHERE EventDateBegin >'01/01/2008' AND (Events.Category LIKE '3' OR Events.Category LIKE '4' OR Events.Category LIKE '5' OR Events.Category LIKE '6' OR Events.Category LIKE '7' OR Events.Category LIKE '8' OR Events.Category LIKE '9' OR Events.Category LIKE '10' OR Events.Category LIKE '11' OR Events.Category LIKE '12' OR Events.Category LIKE '13' OR Events.Category LIKE '14' OR Events.Category LIKE '15' OR Events.Category LIKE '16' OR Events.Category LIKE '17' OR Events.Category LIKE '18' OR Events.Category LIKE '19' OR Events.Category LIKE '20' OR Events.Category LIKE '21' ORDER BY EventName)" 
However if Category isn't a text field it could be simplified much more.

Jared
Hey Jared! GREAT! It works! Thank you so much for your effort and help in this. I am really so happy. :)

Ok just a little bit more. I like to enhance the dateformat such that it is showing DDMMYY. You got any idea how should I change it? As the current results is showing MMDDYY
Jan 9 '08 #13
jhardman
3,406 Expert 2GB
Hey Jared! GREAT! It works! Thank you so much for your effort and help in this. I am really so happy. :)

Ok just a little bit more. I like to enhance the dateformat such that it is showing DDMMYY. You got any idea how should I change it? As the current results is showing MMDDYY
I believe that is actually a system setting (on the server), not set in your scripts but it could possibly be set in the db. I always try to manipulate dates in a non-ambiguous format like "12 Jan 2008" which most applications will recognize as a valid date and they can recognize and store it according to the preference of their program. As far as ASP goes, unless you want to write your own function for converting the date to the format you prefer, you are limited to the formatDateTime() function, and that still arranges according to system preference. Here's a link. This page says it converts to mm/dd/yy, but I think if your system preference is set the other way it goes to dd/mm/yy

Jared
Jan 9 '08 #14
Thank you Jared!

I manage to get it. In case it might be of some help to few of you. This is the code I am using.

varEventDate = FormatDateTime(CDate(rs("EventDateBegin")),1)


Cheers!
Jan 10 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating...
0
by: hismail | last post by:
I am creating a vb.net service that will run AS SERVICE. There is actually a timer; so the timer will run every 2 minutes and see if there are any new ERROR type logs in the APPLICATION logs. And...
0
by: hismail | last post by:
1. hism...@dot-solution.net Aug 16, 2:51 pm show options Newsgroups: microsoft.public.vb.general.discussion From: hism...@dot-solution.net - Find messages by this author Date: 16 Aug 2005...
1
by: mrkselm | last post by:
Hi, I am stuck with a problem in MS Access which does not occur in SQL Server and I have been banging my head against the wall for a couple of days now trying to resolve it. Namely, when I...
4
by: stevetuf | last post by:
I have been tinkering with this for a while now, and I just can't get no satisfaction! I need to create a query which pulls from a table that has three columns: Date, Task and Comment. The final...
0
by: Nyh | last post by:
I tried to explain the best I can but it is very difficult to do. Here it goes. I have three history tables. Teacher, student and school. School and teacher, and school and student are linked...
2
by: scott | last post by:
Hi Everyone, I have a table which has many fields in it but I need to pull some specific info via a query and I don't know if it's possible. I want to run a query which includes two tables....
2
by: ankitmathur | last post by:
Hi Friends, I have been trying to use this query to get all records that will expire within the next 30 days from the current date. While I am getting records with the same query what is...
21
by: Tarscher | last post by:
Hi all, I have events containing attendees (events has many attendees). The attendee table tells whether a user will attend the event or not. I want to build a query that returns all the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.