Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3240520
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:05:41+00:00 2026-05-17T18:05:41+00:00

Short version: When I try to use Access’s DatePart function via ODBC, it cannot

  • 0

Short version: When I try to use Access’s DatePart function via ODBC, it cannot be resolved.

Longer version:

I have a Microsoft Access query which returns rows with a timestamp and a score. I want to sort it by day and then by score – effectively a high-score table for the day.

For want of a better function, I used the DatePart function to extract each of the Year, Month and Day from the timestamp, and ORDER BY them followed by Score.

In Microsoft Access, the query works beautifully.

However, when I use pyodbc to access the same query, the ODBC driver is stumped by the DatePart function, and thinks it is the name of a missing parameter.

What astonished me was that even if I hid the DatePart function, by creating a new HighScore query, and then SELECT * FROM HighScore, it still complained that it couldn’t find the parameter. Apparently, the query’s SQL is being resolved fairly late in the process.

My question is either:

  • How do I resolve the DatePart function in the SQL to allow Access to run it, or
  • What is a right way to sort by the day part of a timestamp over ODBC?

Added additional info:

Seems like overkill, but here’s some code:

import pyodbc
access_db_path = r"<ellided>"
connection_string = 'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+access_db_path
connection = pyodbc.connect(connection_string, autocommit = True)

print "First query"
connection.cursor().execute('SELECT ScoreTime FROM SplitExtendedP1')
print "Worked"

print "Second query"
print connection.cursor().execute('SELECT DatePart("yyyy",ScoreTime) FROM SplitExtendedP1')
print "Doesn't get here."

Here are the results:

First query
Worked
Second query
Traceback (most recent call last):
  File "<ellided>.py", line 16, in <module>
    print connection.cursor().execute('SELECT DatePart("yyyy", ScoreTime) FROM SplitExtendedP1')
pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. (-3010) (SQLExecDirectW)')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:05:42+00:00Added an answer on May 17, 2026 at 6:05 pm

    Are you sure that using quotes "yyyy" instead of apostrophes 'yyyy' is valid in that dialect of SQL?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application to manage user access to files. The short version
Short version of the question: Since I already have TortoiseHg, I right clicked on
Ok, the short version is that I have a Linq entity from a LinqDataSourceUpdateEventArgs
Short version: I want a way to run somefunction(username) and have it return the
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
Short version: assuming I don't want to keep the data for long, how do
Short Version: When I've created a Channel using ChannelFactory on a client which uses
Short of inserting a try/catch block in each worker thread method, is there a
Short version: How can I get a regex that matches a@a.aaaa but not a@a.aaaaa

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.