简体   繁体   English

RODBC-sql保存日期

[英]RODBC - sqlSave date

I use RODBC to connect to a Filemaker database and read/write data. 我使用RODBC连接到Filemaker数据库并读取/写入数据。

I currently fail at writing a date to my database with this code: 我目前无法使用以下代码将日期写入数据库:

sqlQuery(db, "INSERT INTO mytable (a,c) VALUES (98,'01-01-2017')")

R then thows an error: Incompatible types in assignment. R然后引发错误: Incompatible types in assignment.

It works when I reformat column c in the database to 'decimal' and write two numeric values, so I'm pretty sure the only problem is the format of the date. 当我将数据库中的列c重新格式化为'decimal'并写入两个数值时,它可以工作,因此,我很确定唯一的问题是日期的格式。 I tried several arrangements of the data (such as 2017-01-01 , 2017/01/01 , quoting it and so on). 我尝试了几种数据排列方式(例如2017-01-01 2017/01/01 ,引用了数据等等)。 My database takes the data format dd-mm-yyyy if I just enter the data manually, so that's not the problem. 如果我只是手动输入数据,我的数据库将采用dd-mm-yyyy的数据格式,所以这不是问题。

Any suggestions? 有什么建议么?

I just found this FileMaker documentation stating 我刚刚发现此FileMaker文档说明

ExecuteSQL accepts only the SQL-92 syntax ISO date and time formats with no braces. ExecuteSQL仅接受SQL-92语法ISO日期和时间格式,不带花括号。 ExecuteSQL does not accept the ODBC/JDBC format date, time, and timestamp constants in braces. ExecuteSQL在括号中不接受ODBC / JDBC格式的日期,时间和时间戳常量。

And - even more important! 而且-更重要! - this: - 这个:

To apply the correct formatting to dates in an SQL query, use the DATE statement. 要将正确的格式应用于SQL查询中的日期,请使用DATE语句。 If you do not use the DATE statement, ExecuteSQL treats dates as literal strings 如果不使用DATE语句,则ExecuteSQL将日期视为文字字符串

No matter what you are writing, it is taken as a string... 无论您在写什么,它都被当作一个字符串...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM