Invalid Procedure Call on DateDiff with MS Access Driver - ms-access

The following query:
SELECT DateDiff('month',0,'2000-01-01 00:00:00');
Returns a "[ODBC Microsoft Access Driver] Invalid procedure call" error, with the bizarre code of 22018.
Specs:
Microsoft Access Driver version: 4.00.6305.00
Database created with Access 2003
The above appears to be the proper syntax, as calling the function with the current format (no single quotes for month), returns "[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."
So, what is the proper syntax, if I did not get it right? Alternatively, how do I perform a datediff with that version of the driver?

I don't understand how ODBC is involved, but your query won't work in a pure Access context because DateDiff requires "m" as the interval argument for month.
Within Access 2003, this query returns 1201:
SELECT DateDiff('m',0,'2000-01-01 00:00:00');

Related

window function parenthesis error on MYSQL8.0.11

I've working on MYSQL 8.0.11 and testing window functions but getting what I think is an unexpected error via workbench.
SELECT AVG(Volume) OVER(PARTITION BY `Security` ORDER BY DateValue ROWS 19 PRECEDING) AS MAV20
FROM t_EOD_Dly;
In workbenches query window at the Over( I am getting Syntax error: Unexpected '(' (opening parenthesis)
To my best knowledge, brackets are correct. The SQL statement executes correctly with a green tick in the output window.
Interestingly when I drop the same SQL into a stored procedure it won't apply and generates The object's DDL statement contains syntax errors. when attempting to do so.
Is this a bug in build 8.0.11 or am i missing something really simple?
This morning i upgraded both Server and Workbench to 8.0.12 and windows functions now work and I can save to stored procedure.

Undefined function 'mid' in expression in MS Access

I am trying to write a query in MS Access, and receiving the error "Undefined function 'mid' in expression' when I try to execute it.
SELECT MID([ColumnName], 4,2)
FROM tblName
As I understand it, the MID function is the MS Access equivalent to Substring. Both the table and the column definitely exist. What could be causing this error?
Check 'References' in 'Tools' menu in VBA, there must be some 'MISSING' libraries.

Invalid descriptor index on LAST_INSERT_ID after insert

Strange situation with my ODBC code ( called from a C library ). Basically, I have the following sequence of events:
Create insert statement ( just a string )
Call SQLPrepare with that insert statement string
Bind the various parameters ( column values ), using
SQLBindParameter
Call SQLExecute to insert the row ( this works, by the way, as I can
see the row in the MySQL DB )
Create "select last_insert_id()" statement string
NOTE: if in SQL Server mode, we would create a "select ##identity"
statement
Bind column using SQLBindCol - this is where I get the "Invalid
descriptor index" error
NOTE: if in SQL Server mode, this works fine, with no error
Call SQLExecDirect to get the last insert id - this never happens
because of SQLBindCol error
Does the standard MySQL ODBC connector require something special in this situation? Does anyone have an ODBC example of this type of "insert" then "get last insert id" behavior? Maybe I need to call "SQLPrepare" before step 6 ( where I bind the column )? Another way to ask this: Should there be an SQLPrepare call for each SQLExecute or SQLExecDirect call?
I know it works directly in SQL, so the problem is my C ODBC code.
Thanks.
For those who are interested, I ended up changing the above steps by adding an SQLPrepare call between creating the "select last_insert_id()" ( step 5 ) and calling SQLBindCol ( step 6 ). Not sure if that would work for others, but it seems to be working rather well for me.
As for research, I looked all over the place online and never found a really good or clear answer. Most comments were about the SQL involved, not ODBC. And the references to ODBC were vague and did not seem to apply to my situation, from what I could see.
My assumption is that the SqlServer ODBC driver I am using handles the missing prepare statement differently ( maybe even better, but that is debatable ) than my MySql ODBC driver.
SQL Server ODBC driver was the one provided by Easysoft
MySql ODBC driver was the one provided with the standard CentOS install of MySql
Hopefully this will help people. Obviously, if people have a better idea, please tell us.

ssis 2005 query parameter date time cast fail

In my SSIS 2005 package, in OLE DB source (SQL Server 2005), I tried to execute a query with one parameter
The query in the OLE DB source
select
...
from..
where
txn_date_time >= ?
As you can see, the query takes one parameter from variable. The variable is type string and value is 20140622
Got this error in the OLE DB source when run the package.
...
Description: "Invalid character value for cast specification".
Also tried this and got the same error.
txn_date_time >= cast(? as datetime)
The query can be run perfectly in SSMS, e.g.
select
...
from..
where
txn_date_time >= '20140622'
It seems to me that SSIS only allow parameter of type date time to be passed to the query because txn_date_time is type date time. Do I have to change the variable to type Date time?
Check the data type of the value returned by your query and the data type of the parameter that you are mapping it to. They should be compatible else you get such cast exceptions.

JdbcOdbc Driver Fails to Find the Replace Function in MS Access

Good people,
I am trying to execute an SQL query against an MS Access database through my Java program. The program uses the JdbcOdbc driver. The query contains the inbuilt Replace function in it. It looks something like this:
SELECT Replace(first_name, '-', ' ') AS f_name FROM patient WHERE....
The program fails with the following error: "[Microsoft][ODBC Microsoft Access Driver] Undefined function 'Replace' in expression."
How can this be? Other functions such as LCase and Trim work just fine. Also, the Replace function works okay when executed directly on the back end.
Your query can not use the Replace() function unless it is run from within an Access session.
The situation is the same as if you were attempting to use a user-defined function. The db engine can only utilize those with assistance from the Access expression service, which is only available from within an Access session.