필터 지우기
필터 지우기

database toolbox - sql query problems

조회 수: 4 (최근 30일)
Tom Hissel
Tom Hissel 2011년 4월 26일
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
Oleg Komarov 2011년 4월 26일
POst the error message: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers
Tom Hissel
Tom Hissel 2011년 4월 26일
done, didnt do that before because it doesn't give significant information.

댓글을 달려면 로그인하십시오.

채택된 답변

Tom Hissel
Tom Hissel 2011년 4월 26일
OK after hours of puzzling I found a syntax that does get accepted by matlab and sql :)
this one works: 'SELECT ALL Systeemtijd FROM "SWS_Pand OS1 GRFMET 10" WHERE Systeemtijd>#02/26/2011 13:36:00#'
Thanks for your responses though! cheers

추가 답변 (2개)

Oleg Komarov
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'} '
  댓글 수: 1
Tom Hissel
Tom Hissel 2011년 4월 26일
SELECT ALL Systeemtijd FROM "SWS_Pand OS1 GRFMET 1" WHERE (Systeemtijd >{ts '2011-02-25 16:56:00'})

댓글을 달려면 로그인하십시오.


Clemens
Clemens 2011년 4월 26일
seems the string's not valid.
did you try replacing the apostrophes with ''(2 apostrophes) or " ?
  댓글 수: 1
Tom Hissel
Tom Hissel 2011년 4월 26일
yes. using quotation marks I get the following error:
??? Error using ==> database.fetch at 37
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Systeemtijd > ts [2011-02-25 16:56:00]}'.
Error in ==> queryoefenen at 27
Tijd = fetch(conn, 'SELECT ALL Systeemtijd FROM "SWS_Pand OS1 GRFMET 1" WHERE Systeemtijd > {ts "2011-02-25 16:56:00"} ');
Again.. syntax is not accepted.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by