Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Fernan
Partner - Contributor III
Partner - Contributor III

ODBC Connection to csv issue

Hello, I am trying to make an Odbc connection to a series of * .csv files,
to load their content in a table, but I receive a series of errors,
I would appreciate any contribution to solve it. Attached the errors and part of the code,
Thank you very much in advance.

The code is this:

FOR EACH File in FileList('*.CSV');

ODBC CONNECT32 TO [Csv FilesOk;DBQ=$(File)];

tables:
SQLtables;

DISCONNECT;

Let count = SubStringCount(File,'\');
Let tablename = left(Subfield(File,'\',$(count)+1),len(Subfield(File,'\',$(count)+1))-5);

FOR i = 0 to NoOfRows('tables')-1

LET sheetName = purgeChar(purgeChar(peek('TABLE_NAME', i, 'tables'), chr(39)), chr(36));

if(Exists(TableName($(sheetName)))) then

Concatenate
'$(tablename)':
Load *
From $(File)(ooxml, embedded labels, table is [$(sheetName)]);

ELSE

NoConcatenate
'$(tablename)':
Load *
From $(File)(ooxml, embedded labels, table is [$(sheetName)]);

ENDIF

NEXT i;

Drop table tables;

Next File;

2 Replies
Frank_Hartmann
Master II
Master II

Try this:

SET ErrorMode=0;
FOR EACH File in FileList('*.csv');
ODBC CONNECT32 TO [Excel Files;DBQ=$(File)]; 

tables:
SQLtables;
DISCONNECT;
Let count = SubStringCount(File,'\');
Let tablename = 'Table '& left(Subfield(File,'\',$(count)+1),len(Subfield(File,'\',$(count)+1))-4);
FOR i = 0 to NoOfRows('tables')-1
LET sheetName = purgeChar(purgeChar(peek('TABLE_NAME', i, 'tables'), chr(39)), chr(36));

NoConcatenate
'$(tablename)':
Load *
From $(File)(txt, codepage is 28591, embedded labels, delimiter is ';', msq);

NEXT i;
Drop table tables;
Next File;
Fernan
Partner - Contributor III
Partner - Contributor III
Author

Hi Frank, I have tried several .csv files but it keeps giving me an error.
I am attaching a screenshot and the message it gives me.

Thank you very much in advance.

Greetings

2021-08-04 22_06_25-Screenshot-1.png

Connecting to Excel Files;DBQ=C:\Fenix\Modelo de Datos\KPIS\Nuevosdatos\tablita.csv;
Failed to connect
Connector connect error: SQL##f - SqlState: S1000, ErrorCode: 4294962281, ErrorMsg: [Microsoft][Controlador ODBC Excel] La tabla externa no tiene el formato esperado.
ODBC CONNECT32 TO ***