Importing data from Microsoft Access w/ SQL query
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jared
el 29 de Nov. de 2014
Comentada: Jared
el 29 de Nov. de 2014
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 comentarios
Respuesta aceptada
Geoff Hayes
el 29 de Nov. de 2014
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).
Más respuestas (0)
Ver también
Categorías
Más información sobre Database Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!