How to get more than one SQL table data using MATLAB?
Mostrar comentarios más antiguos
I have stored procedure which returns three tables output. Somehow MATLAB code ony shows first table output. Is there anyway I can retrieve the second and third table output?
SQL Store Procedure:
CREATE PROCEDURE [dbo].[GetData]
@ID int
AS
BEGIN
SELECT Top 10 * FROM TableA
SELECT Top 10 * FROM TableB
SELECT Top 10 * FROM TableC
END
MATLAB code:
setdbprefs('DataReturnFormat','cellarray');
curs = exec(conn, 'GetData');
curs = fetch(curs);
outputdata = curs.Data;
close(curs);
Respuestas (1)
Florian Bidaud
el 16 de Ag. de 2023
Hi,
You can just loop over your commands with select:
letter = {'A' 'B' 'C'}
for i = 1:3
curs{i} = select(['SELECT Top 10 * FROM Table' letter{i}]);
end
results = executeSQLScript(conn, 'GetData.sql');
9 comentarios
Monkey Coder
el 16 de Ag. de 2023
Florian Bidaud
el 16 de Ag. de 2023
can you show the output of writing curs in the commmand window ?
Monkey Coder
el 16 de Ag. de 2023
Florian Bidaud
el 16 de Ag. de 2023
what if you do [curs1, curs2, curs3] =exec(conn, 'GetData'); ?
Monkey Coder
el 16 de Ag. de 2023
Florian Bidaud
el 16 de Ag. de 2023
And with your first command do you get TableA or TableC as as the output ?
Monkey Coder
el 16 de Ag. de 2023
Florian Bidaud
el 16 de Ag. de 2023
I think the only way to do it like you want is by using this method : https://uk.mathworks.com/matlabcentral/answers/96318-how-can-i-query-a-database-to-extract-data-from-multiple-tables
Monkey Coder
el 16 de Ag. de 2023
Categorías
Más información sobre Import Data Programmatically en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!