フィルターのクリア

SQL query from Matlab

3 ビュー (過去 30 日間)
Gurvinder
Gurvinder 2013 年 8 月 18 日
Hi i am trying to format my sqlstr going into mysql but can't seem to get the format correct using sprintf function
here is the code i am using:
TableType = char(PramTest); TableRow = char(DataSelection);
%TableType reurns the value of 'SPEC' and TableRow = '1'.
sqlStrtest= sprintf('select * from %s where id%s = %d', TableType, TableType, TableRow); disp(sqlStrtest)
This reurns the following:
select * from where idSPEC = 83select * from where idPEC = 49
What i need it to return is
select * from SPEC where idSPEC = 1
can you help me please in quiring a correct format.
thank you

採用された回答

the cyclist
the cyclist 2013 年 8 月 18 日
編集済み: the cyclist 2013 年 8 月 18 日
Notice that
TableRow = '1';
and not
TableRow = 1;
TableRow is stored as a string, not a number, so that is how you should specify it in sprintf:
sqlStrtest= sprintf('select * from %s where id%s = %s', TableType, TableType, TableRow);
[See that I changed your %d to %s.]
You got the mysterious 49 because the number 1 is the 49th ASCII character.
  2 件のコメント
Gurvinder
Gurvinder 2013 年 8 月 18 日
fantastic, thank you, is there an online tutorial which one can learn more about this from, the Matlab documents sometimes confuse me as i am very new to programming in general.
Thank you again
the cyclist
the cyclist 2013 年 8 月 18 日
There are lots of resources online for learning MATLAB. Here is one good starting point: http://www.mathworks.com/academia/student_center/tutorials/launchpad.html

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by