0

So I am accessing an MSAccess database using PDO (ODBC). I am trying to get all records from the current week NOT the past seven days. Here is my query:

SELECT * 
FROM tblBilling 
WHERE ((
      Year(DateOfService) = Year(Date()) 
  And DatePart("ww", DateOfService, 0) = DatePart("ww", Date(), 0)
))
ORDER BY DateOfService, TimeOfService

Obviously this works in MSAccess, but when using it from the web app I get the following error:

SQLSTATE[07002]: COUNT field incorrect: 
    -3010 [Microsoft][ODBC Microsoft Access Driver] 
    Too few parameters. Expected 1. 
    (SQLExecute[-3010] at ext\pdo_odbc\odbc_stmt.c:254)

I can't seem to figure this out. I must be overlooking something and my brain is now turning to mush. I know if I remove DataPart it will run the query and not return an error, but then it will not do what I need it to do.

Thanks for all the help!

Extra code as requested:

try
{
    $pdo = new PDO('odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq='.DB_NAME.';Uid=');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $myPDO = $pdo->prepare($query);
    $myPDO->execute(); 

    $result = $myPDO->fetchAll();
} catch(PDOException $e)
{
    echo $e->getMessage();
}
2
  • Can you show us your code? It's the only way people will be able to diagnose your problem. Commented Dec 7, 2011 at 3:23
  • I don't think you need those parentheticals around the WHERE statement. Commented Dec 7, 2011 at 4:36

2 Answers 2

1

For anyone wanting to know. If you are running queries against an MSAccess database the query syntax is not going to be the same from what you are use to. This is how I got it to work. I changed the double quotes around ww to single quotes.

SELECT * 
FROM tblBilling 
WHERE ((Year(DateOfService) = Year(Date()) 
AND DatePart(\'ww\', DateOfService, 0) = DatePart(\'ww\', Date(), 0)))
ORDER BY DateOfService, TimeOfService
Sign up to request clarification or add additional context in comments.

Comments

0

It appears that the Datepart section of your query is not being recognized as function by your ADODB connection (it thinks it is a parameter).

This doesn't help you with your exact problem.... but here is an alternate way to get where you want to go.

I have in the past solved issues of this nature by creating a calendar table (for financial calendars which are somewhat aribitrary from a logic standpoint). This is an idea I got from Data Analysis Using SQL and Excel

The table looks something like this.

Calendar table sample

You can easily put 50 years worth of calendar days without causing any type of preformance issue. You can then get your date buckets as required by joining to the calendar table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.