?
Solved

Need to show full results from a query

Posted on 2011-02-15
12
Medium Priority
?
244 Views
Last Modified: 2012-08-14
I have a data type field (date/time) "SubDate" that contains information in the following format  mm/dd/yyyy time or for example:  5/7/2008 1:42:33 PM.  My search page pulls out the years (yyyy) from the SubDate field.  

Now I want to pull up all data that contains the specific year selected in the search page.  For example, if I selected 2010, then the results page will display all of SubDate's data that contain the year 2010 in it.

As of right now, here is my Select statement:
SELECT * FROM district WHERE SubDate = #"&Request.QueryString("SubDateYear")&"# ORDER BY SubDate DESC

And I receive the following error message:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression 'SubDate = ##'.

Obviously, it is looking only for the year when the field contains 5/7/2008 1:42:33 PM in it.

Any suggestions or recommendations is greatly appreciated.

Thank you.
0
Comment
Question by:arendt73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 8

Expert Comment

by:rushShah
ID: 34898994
hi try Year function..


SELECT * FROM district WHERE Year(SubDate) = #"&Request.QueryString("SubDateYear")&"# ORDER BY SubDate DESC

Open in new window

0
 

Author Comment

by:arendt73
ID: 34899331
I get the following error when I applied the suggestion:

[Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression 'Year(SubDate) = ##'.

/cmecf/review=ecf_district_past.asp, line 14
0
 
LVL 11

Expert Comment

by:Ovid Burke
ID: 34899383
Try this:
"SELECT * FROM district WHERE DATEPART(year, 'SubDate') = #" & Request.QueryString("SubDateYear") & "# ORDER BY SubDate DESC" 

Open in new window

0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:arendt73
ID: 34899444
The second recommendation was applied and I gt the following error message:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression 'DATEPART(year, 'SubDate') = ##'.
0
 
LVL 11

Expert Comment

by:Ovid Burke
ID: 34899717
Then try this:
"SELECT * FROM district WHERE DATEPART(year, SubDate) = '" & Request.QueryString("SubDateYear") & "' ORDER BY SubDate DESC"

Open in new window

0
 

Author Comment

by:arendt73
ID: 34899751
Sorry again. I get the following error:

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

/cmecf/review=ecf_district_past.asp, line 14
0
 
LVL 11

Accepted Solution

by:
Ovid Burke earned 1500 total points
ID: 34900165
Sorry, I assumed you were using SQL Server. It is only now I am noticing it's Access.
"SELECT * FROM district WHERE year(SubDate) = " & Request.QueryString("SubDateYear") & " ORDER BY SubDate DESC"

Open in new window

0
 

Author Comment

by:arendt73
ID: 34900250
My apologizes, but I receive this error message when I applied the last recommendation.

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'year(SubDate) ='.

The search page contain the POST method so I changed Request.QueryString to Request.Form.  Regardless, I continue to get errors.  And yes, the information resides in Access.
0
 

Author Comment

by:arendt73
ID: 34900565
I ended up using

"SELECT * FROM district WHERE Year(SubDate) = '"&Request.Form("SubYearDate")&"'  ORDER BY SubDate DESC"

Which did the trick and gave me the results I looked for. Thank you.
0
 
LVL 35

Expert Comment

by:ste5an
ID: 34905359
hi,

while it can be done with Access as back-end for small sites when the data access is carefully designed, I would really recommend that you use at least SQL Server 2008 R2 Express as database back-end.


mfG
--> stefan <--
0
 

Author Comment

by:arendt73
ID: 35044886
Used someone else's assistance.
0
 

Author Closing Comment

by:arendt73
ID: 35044887
Used some of suggestions to resolve my issue.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question