Hi Vanessa,
The issue you're encountering with padded blank spaces in nvarchar columns is typically related to how the data is being inserted into the database. This can be influenced by the ODBC driver or the database settings. Here are steps and considerations to address this issue:
Steps to Avoid Padding in nvarchar Columns
- Trim Data Before Insert: Ensure that the data you are inserting does not have trailing spaces.
- Use Parameterized Queries: This can sometimes help in ensuring that the data is inserted correctly without additional padding.
Here is the refrence code you can follow:
% Establish connection to the SQL Server database
conn = database('DB', 'user', 'pwd', 'Vendor', 'Microsoft SQL Server', 'Server', 'your_server_name', 'PortNumber', 1433, 'AuthType', 'Windows');
% Define the column names
colnames = {'"Vessel"', '"Filepath"', '"Date"', '"Review"'};
% Trim the data to remove trailing spaces
dataTrimmed = cellfun(@strtrim, report2, 'UniformOutput', false);
% Insert the trimmed data
datainsert(conn, '"Table"', colnames, dataTrimmed);
% Close the database connection
close(conn);
I hope it helps!