Borrar filtros
Borrar filtros

How to get more than one SQL table data using MATLAB?

2 visualizaciones (últimos 30 días)
Monkey Coder
Monkey Coder el 16 de Ag. de 2023
Comentada: Monkey Coder el 16 de Ag. de 2023
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
Florian Bidaud el 16 de Ag. de 2023
Hi,
First, exec is not recommended, you should use execute instead.
Plus, for select queries, it is better to use select function.
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
But for running this script and get several outputs, you can use executeSQLScript.
results = executeSQLScript(conn, 'GetData.sql');
  9 comentarios
Monkey Coder
Monkey Coder el 16 de Ag. de 2023
i see, it is ok. Thanks for checking.

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by