database toolbox - sql query problems
1 次查看(过去 30 天)
显示 更早的评论
Im browsing access databases using matlab database toolbox and sql queries.
Simple queries work fine but when I want to use 'where' statements in combination with time/date columns (timestamps) I get in trouble. 'Systeemtijd' is a table in the database containing time indication in the format: 2011-02-25 16:56:00.
no problem: Time = fetch(conn, 'SELECT ALL Systeemtijd FROM "SWS_Pand OS1 GRFMET 1" ');
problematic: Time = fetch(conn, 'SELECT ALL Systeemtijd FROM "SWS_Pand OS1 GRFMET 1" WHERE Systeemtijd > {ts'2011-02-25 16:56:00'} ');
This kind of query works fine in access and in excel but for some reason the syntax is not accepted by matlab. Likely the reason is that matlab ends the query at the second ' where the other programs do not.
What is a working code/syntax to do a query like this in matlab?
Thank you
there was a typo before. I changed it.
The error message is just this one: ??? Error: File: queryoefenen.m Line: 27 Column: 99 Unexpected MATLAB expression.
It appears because matlab closes the query at the use of an apostrophe.
2 个评论
Oleg Komarov
2011-4-26
POst the error message: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers
采纳的回答
更多回答(2 个)
Oleg Komarov
2011-4-26
I doubt this syntax is accepted by SQL:
'SELECT ALL Systeemtijd FROM "SWS_Pand OS1 GRFMET 1" WHERE Systeemtijd > ts{'2011-02-25 16:56:00'} '
Clemens
2011-4-26
seems the string's not valid.
did you try replacing the apostrophes with ''(2 apostrophes) or " ?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!