MATLAB: How to insert cell array of double in to database table

databaseDatabase Toolbox

I am trying to insert cell array that contains double data.how to insert mxn double data into database table field. For example, the sample code is
tablename = 'LabelData1';
data = ([346565774,4637857]);
data = table(data);
sqlwrite(conn,tablename,data,'ColumnType',{"double"})
but i am getting folling error
_ _Error using database.odbc.connection/sqlwrite (line 102)
ODBC JDBC/ODBC Error: ODBC Driver Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ')'..__
I am using MS SQL server

Best Answer

Since double is not a valid data type in SQL Server, you need to use numeric instead. Also, you need to insert each data to each column of SQL Server. The following will work.
tablename = 'LabelData1';
data = table(346565774, 4637857);
sqlwrite(conn,tablename,data,'ColumnType', ["numeric" "numeric"])
UPDATED
I don't think it is possible to insert multiple numeric values in a single column, but there's a workaround. The following codes insert multiple values as a character.
tablename = 'LabelData1';
data = ["97.877049180327900,67.666276346604180,1.669320843091335e+02,1.247775175644028e+02"];
data = table(data);
sqlwrite(conn,tablename,data,'ColumnType', "varchar(255)")
The data will be inserted in one column as varchar.
After that, you can read from this table and convert the data to double to use it in your another processing.
data2 = sqlread(conn, tablename);
data2 = data2.data;
data2 = sscanf(data2{:}, '%f,%f,%f,%f');
Related Question