Solved

Need to show full results from a query

Posted on 2011-02-15
12
238 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 32

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
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…

747 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

10 Experts available now in Live!

Get 1:1 Help Now