Solved

Need to show full results from a query

Posted on 2011-02-15
12
243 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 500 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 34

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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

627 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