sqlwrite only writes 6 digits to Access Database

10 visualizaciones (últimos 30 días)
Steven Plocker
Steven Plocker el 25 de Ag. de 2022
Respondida: Rahul el 7 de Nov. de 2024 a las 9:48
I'm trying to write an Excel date code to an Access database in the format: 44798.6912268518
but when I open the Access database, the date code is written as 44798.7.
Is there a way to write more than 6 digits to an Access database without changing the data type to a string?

Respuestas (1)

Rahul
Rahul el 7 de Nov. de 2024 a las 9:48
I understand that currently while accessing data from database, you are obtaining the number in a short format. You can consider defining 'format long' before writing the data which can consider approximately 15 decimal places for double-precision numbers. Here is an example:
% I have taken 'conn' and 'tablename' as variables for connection with the database, can be adjusted
% Set the display format to long
format long
dateCode = 44798.6912268518;
data = table(dateCode, 'VariableNames', {'yourFieldName'});
sqlwrite(conn,tablename,data)
Another approach can be to use the 'vpa' function provided by the Symbolic Math Toolbox which enables to define number of significant decimal places required. Here is an example:
dateCode = vpa(44798.6912268518, 30); % Here I have taken 30 as an example for required decimal places
data = table(dateCode, 'VariableNames', {'yourFieldName'});
sqlwrite(conn,tablename,data)
You can refer to the following MathWorks documentations to know more about these functions:
Hope this helps! Thanks.

Community Treasure Hunt

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

Start Hunting!

Translated by