Hello Thodoris Polychronopoulos,
Welcome to the MS Q&A platform.
Can you try use the FIELDQUOTE
property in your code?
The FIELDQUOTE
property specifies a character that will be used as the quote character in the CSV file.
Specifying the FIELDQUOTE
property can be helpful when the default behavior does not correctly interpret the quoted values, or when you need to handle CSV files with different quoting characters.
By explicitly setting the FIELDQUOTE
property, you can ensure that the OPENROWSET
function correctly handles the quoted values in your CSV file, regardless of the default behavior or any variations in the quoting characters used in different files.
CREATE VIEW [dbo].[view] as
SELECT
fields
FROM
OPENROWSET(
BULK 'url/*.csv',
FORMAT = 'CSV',
PARSER_VERSION = '2.0',
FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n',
HEADER_ROW = TRUE,
first_row = 1,
FIELDQUOTE = '"'
)
AS ROWS
;
GO
If the above solution doesn't help, then please check the CSV file for any inconsistencies in the quoting or delimiters. It's possible that there might be an issue with the file itself, such as unmatched quotes or incorrect delimiters.
You can open the CSV file in a text editor and inspect the contents to identify any issues. If you find any inconsistencies, correct them and try running the OPENROWSET
function again with the updated file.