필터 지우기
필터 지우기

How can I pull data from Access without hard coding the table name?

조회 수: 1 (최근 30일)
L
L 2017년 2월 11일
댓글: L 2017년 2월 13일
Hello everyone,
I am trying to import data from an Access database in the following manner:
conn = database.ODBCConection(databasename,username,password);
tablename = input('Enter tablename: ','s'):
curs = exec(conn,'SELECT * from %s',tablename);
curs = fetch(curs);
Where databasename, username and password are all user inputs like tablename. The exec command works if I simply put:
curs = exec(conn,'SELECT * from SalesLastMonth');
but I want to be able to make it more adaptable in terms of which table the script pulls from.
Any ideas on what the syntax is to make this possible? I greatly appreciate any assistance!
Thank you,
L

채택된 답변

Guillaume
Guillaume 2017년 2월 11일
Nearly got it right:
exec(conn, sprintf('SELECT * from %s', tablename))

추가 답변 (0개)

카테고리

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