Hi Cristian,
You can correctly execute your SQL query in MATLAB by ensuring proper syntax and concatenation of strings for your SQL statement. MATLAB "fetch" function doesn't interpret SQL differently from Workbench, but improper string concatenation or syntax can cause issues.
You can fix the errors possibly by following the below steps:
- Proper parentheses in SQL queries ensure correct logical grouping.
- You can use "sprintf" or "strcat" to concatenate strings cleanly and avoid errors.
% Based on the SQL query provided above
% Assuming caseta1, caseta2, caseta3, caseta4 are numeric variables
sqlquery = sprintf(['SELECT * FROM prices.prices WHERE ' ...
'(Var5 <= %f AND Var5 >= %f OR Var6 <= %f AND Var6 >= %f OR Var7 <= %f AND Var7 >= %f) ' ...
'AND (Var8 <= %f AND Var8 >= %f OR Product <= %f AND Product >= %f OR Var10 <= %f AND Var10 >= %f)'], ...
caseta2, caseta1, caseta2, caseta1, caseta2, caseta1, ...
caseta4, caseta3, caseta4, caseta3, caseta4, caseta3);
selectie = fetch(conn, sqlquery);
The above code ensures the SQL query functions appropriately through proper paranthesis usage.
Additionally you can refer to the detailed MathWorks documentation on "fetch": https://www.mathworks.com/help/database/ug/database.odbc.connection.fetch.html along with the several examples provided.