Last active
December 25, 2015 03:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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