Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfbecher/6907781 to your computer and use it in GitHub Desktop.
Save ralfbecher/6907781 to your computer and use it in GitHub Desktop.
Handle square brackets used in the field names (eg. CSV file) with QlikView. S olve it with a three step approach: 1. read field names as a list from the header row (transpose) into a mapping table and replace square brackets with paranthesis (or else) 2. load data with no labels (field names @1, @2 etc.) 3. rename field names using a mapping table
// load header row
Header:
FIRST 1 LOAD @1:n as First_Line
FROM flatfile.csv
(fix, codepage is 1252);
// load list of fields for renaming, replace square brackets with paranthesis
Map_Fields:
MAPPING LOAD '@' & RowNo() as Field1, Replace(Replace(SubField(First_Line, '|'), '[', '('), ']', ')') as Field2
Resident Header;
Drop Table Header;
// load data without field names (save scripting work with aliases)
data:
LOAD @1,
@2,
@3,
@4,
@5,
@6,
@7
FROM flatfile.csv
(txt, codepage is 1252, no labels, delimiter is '|', msq, header is 1 lines);
//
RENAME Fields using Map_Fields;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment