Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Managing data retrieved from SQL within Matlab

2 vues (au cours des 30 derniers jours)
Chris Dischner
Chris Dischner le 25 Oct 2016
Clôturé : MATLAB Answer Bot le 20 Août 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]);

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by