Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Managing data retrieved from SQL within Matlab

2 visualizaciones (últimos 30 días)
Chris Dischner
Chris Dischner el 25 de Oct. de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I've configured Matlab code to retrieve data I have in SSMS, which I'd ultimately like to compare to data I'm importing via the import wizard.
I import the second dataset as a table via the 'Import Data' wizard, with relevant columns 'Date', stored as datetime, and an ID column stored as text.
I'm able to pull in the SQL data and create a table out of it, also with 'Date' and ID columns, but I get an error:
"Left and right key variables 'Date' and 'Date' are not comparable because one is a non-cell."
This seems related to the SQL 'Date' data being stored as cell type. I've tried setting the 'DataReturnFormat' to table as part of my read in from SQL, but the underlying data still seems to be saved in the table as a cell. I've also tried combinations of reading in from SQL as cell and converting to a table using the array2table and cell2table functions but neither seems to allow me to correct this.
Is there a way to retrieve data from SQL that will allow me to mirror a similar import from an Excel file to a Matlab table? The following is the code I'm using to do the SQL retrieval and the subsequent inner join to the data imported using the import wizard. Error I'm getting is as above.
conn = database('myDB','','',...
'Vendor','Microsoft SQL Server','Server','myServer',...
'AuthType','Windows')
sqlquery = 'select * from myDB.mySchema.myTable';
curs = exec(conn,sqlquery);
setdbprefs('DataReturnFormat','table');
curs = fetch(curs);
mySQLData = curs.Data;
% columns 1 and 2 are both 'Date' and 'ID' for each variable
[C,~,~] = innerjoin(myImportData,mySQLData,'Keys',[1,2]);

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by