Assign two variables to a SQL Query

9 ビュー (過去 30 日間)
Cristian Martin
Cristian Martin 2022 年 6 月 12 日
コメント済み: Rik 2022 年 6 月 15 日
Hi,
x=TOYOTA;
Y=9981;
conn = database('baza_date','','');
sqlquery = ['UPDATE prices.prices SET Product =',num2str(x), 'WHERE Crt = ', num2str(y)];
data = fetch(conn,sqlquery);
exec(conn,sqlquery);
close(conn);
Error:
Error using database/fetch (line 40)
[MySQL][ODBC 8.0(a) Driver][mysqld-8.0.29]You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'Crt = 9981' at line 1
Error in bdmodify>pushbutton12_Callback (line 509)
data = fetch(conn,sqlquery);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in bdmodify (line 42)
gui_mainfcn(gui_State, varargin{:});
If I use a single variable for query it worked if I use both i recieve this error, i guess i didn't write the code ok, do you know?

採用された回答

Rik
Rik 2022 年 6 月 13 日
I suspect you're missing a space before 'WHERE'. I can recommend using sprintf to avoid such errors.
  2 件のコメント
Cristian Martin
Cristian Martin 2022 年 6 月 15 日
Indeed that was it, thanks!
Rik
Rik 2022 年 6 月 15 日
You're welcome

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by