Solved

Need to show full results from a query

Posted on 2011-02-15
12
239 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
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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 33

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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
syadmin MSSQL 2 58
SQL Query 34 82
Recordset containing single quotes 8 23
Extract string portion 2 14
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now