Importing data from Microsoft Access w/ SQL query
2 ビュー (過去 30 日間)
古いコメントを表示
I have the database toolbox and have had no issues exporting data from MATLAB into Access using the ODBC connection process. However, it's taken me awhile to figure out how to import data into MATLAB from my Access database using SQL queries in MATLAB. I'm trying to understand why this code doesn't work (I don't have the connection code below but that's not the issue...MATLAB establishes the connection just fine):
A='MKT';
curs = exec(conn,['select Period,Ticker from MonthlyReturns where Ticker = ',A]);
curs = fetch(curs)
While this code does:
A='MKT';
curs = exec(conn, ['select Period,Return from MonthlyReturns where Ticker = ''', A, ''''])
curs = fetch(curs)
Just not clear to me exactly why all the additional apostrophes are needed.
Thanks,
JK
0 件のコメント
採用された回答
Geoff Hayes
2014 年 11 月 29 日
Jared - look at the two queries (as strings)
>> A = 'MKT';
>> query1 = ['select Period,Ticker from MonthlyReturns where Ticker = ',A];
>> query2 = ['select Period,Return from MonthlyReturns where Ticker = ''', A, ''''];
query1 =
select Period,Ticker from MonthlyReturns where Ticker = MKT
query2 =
select Period,Return from MonthlyReturns where Ticker = 'MKT'
Your Ticker field data type is char/string, so you need to wrap the condition for it (in your where clause) in single quotes. This is just usual SQL syntax (and is not MATLAB related).
その他の回答 (0 件)
参考
カテゴリ
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!