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

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 日

0 投票

Nearly got it right:
exec(conn, sprintf('SELECT * from %s', tablename))

1 件のコメント

L
L 2017 年 2 月 13 日
Thanks Guillaume! Learned from the best haha.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

L
L
2017 年 2 月 11 日

コメント済み:

L
L
2017 年 2 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by