Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to show full results from a query

Posted on 2011-02-15
12
Medium Priority
?
245 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 

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 36

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…
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…
Suggested Courses

971 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