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("E ventName")%> - <%=rs("EventDat eBegin")%>"><%= rs("EventName") %> - Date: <%=rs("EventDat eBegin")%>
Can anybody advice if I am doing the right way?
14 2222 jhardman 3,406
Recognized Expert Specialist
The date should be enclosed in pound signs: - EventDateBegin >#01/01/2008#
Let me know if this helps.
Jared
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?
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.
jhardman 3,406
Recognized Expert Specialist
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
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
:)
jhardman 3,406
Recognized Expert Specialist
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
jhardman 3,406
Recognized Expert Specialist
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: - SELECT * FROM [works] WHERE [date-posted] > '11/1/2007'
jhardman 3,406
Recognized Expert Specialist
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 - 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 premiums are dependant on the country in which the client is in.
Therefore, we have a Country table, with its list of rates, a client table
and then the property table. Getting this is great, works fine, easy!
Problem is, now I need to work out a...
|
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 if
there are then it will send an email to me ( or whoever I want to
specify). The thing that I can not figure out is how do I create the
query so it queries only thing in the past 2 minutes. If I take the
TimeWritten out of my query it works...
|
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 11:51:51 -0700
Local: Tues, Aug 16 2005 2:51 pm
Subject: Query Eventlog by Timewritten field.
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse
|
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 execute the following
query in Access not all records that fit the condition are returned,
and when I run this same query in SQL Server all the records I want are
retrieved.
The query is:
|
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 output is to a pane in a month-to-view calendar. Right now, the data might come out a bit like this:
June 1, 2007Los Angeles, Mexican Eatery This will be a worthwhile venture
June 2, 2007Similar task - set a poem on a backdrop of Galicia Good,...
| |
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 together.
I need to make a query that makes in one query a temporary table that list all the students that had a teacher change at some given date in the past.
For example:
If I give the query the following date 01/01/2007 it needs to give me all...
|
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. Participants and Payments.
They are linked so that a participant can make many payments and a report
can then be printed on all payments that participant has made.
What I want to do is have a field in the payments table that has a "PaidTo"
|
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 bothering is I'm also getting records for the days past by.
Select AccountId, ExpiryDate, DATEDIFF(DAY,GETDATE(),ExpiryDate) as DaysLeft From Usr_Accounts
WHERE Status='Active'
AND DATEDIFF(DAY,GETDATE(),ExpiryDate) < 31
|
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 different events to a user
and if he will attend the event or not (or hasn't filled it in yet)
the returned result could be something like:
event.id attendees.user_id attendee.present
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |