0

这是我的 SELECT 查询代码。SELECT * FROM TableName WHERE (DateField = Date)

 function out = SQL_Simple( DBName, TableName, Date, DateField, SortField, Limits )

 logintimeout(60);
 conurl = ['jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=' DBName];
 conn = database('','','','sun.jdbc.odbc.JdbcOdbcDriver', conurl);


 Limits = Limits + 1;
 sql = ['SELECT * FROM ' TableName ];
 sql = [sql ' WHERE (' DateField ' = ' Date ')'];

 interest = fetch(exec(conn, sql));


 %sql = [sql ' ORDER BY ' SortField ' DESC' ];
 %sql = [sql ' LIMIT ' Limits];

 close(conn);
 out = interest.Data;
 end

它不起作用。

这个查询有什么问题?

DateField有类型adDateDate有格式dd.mm.yyyy

ps:

这是数据库中的表:

DBTable.Name = "MyTable"
DBTable.Columns.Append "StrField", adVarWChar, 160
DBTable.Columns.Append "DoubleField", adDouble, 40
DBTable.Columns.Append "IntField", adInteger
DBTable.Columns.Append "CurField", adCurrency
DBTable.Columns.Append "Today", adDate

DateField='Today'. (在matlab代码中)

我试图写这样的东西:

 sql = ['SELECT * FROM ' TableName ];
 sql = [sql ' WHERE (' DateField ' = ''' Date ''');' ];

它也不起作用:((在这里Date = '2010-12-31 00:00:00.0',DateField = 'Today'

4

1 回答 1

0

如果您发布实际的错误消息,它会有所帮助。不过,在这种情况下,我认为一个问题是日期比较。您需要在“日期”周围加上引号。尝试:

sql = [sql ' WHERE (' DateField ' = ''' Date ''')']; 

对于第二个 SQL 行。

于 2012-05-08T18:19:14.773 回答