Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have loaded a table ('FACT') that contains 234 columns of data.
I want to create a new table ('FIELDS') that has 1 column only, containing the names of those 234 columns, ie. a table with 1 column containing 234 values.
Can this be done? If so, how?
Cheers
Thanks for the suggestions, but none of them worked.
I eventually solved it by constructing a string of field names delimited by a carriage return (ASCII code 13).
The code I used was:
set vList=;
set vDelimiter=CHR(13);
for i = 1 to NoOfFields('FACT')
let vFieldName = FieldName($(i), 'FACT');
let vList = '$(vList)' & $(vDelimiter) & '$(vFieldName)';
next i
TMP:
load * inline [
COLUMN_NAME
$(vList)
];
COLUMNS:
noconcatenate
load COLUMN_NAME
resident TMP
order by COLUMN_NAME asc;
drop table TMP;
Not sure, I understand your issue. Can you explain little more or try this way for a while?
Table:
Mapping Load * From FACT;
FIELDS:
Load *, ApplyMap('Table', 'Primary Field', 'NA') as Primary
From Table1;
Hi Hammond,
I think you should used Cross Table.
Hope this help
Justin.
Try this? Reference taken from here: How to get a list of fields in load script?
FACT:
LOAD yourcolumns,
FROM yoursource;
Fields:
FOR i = 1 to NoOfFields('FACT')
Fields:
LOAD
FieldName($(i),'FACT') as FieldNames
AutoGenerate NoOfFields('FACT')
;
NEXT i
Thanks for the suggestions, but none of them worked.
I eventually solved it by constructing a string of field names delimited by a carriage return (ASCII code 13).
The code I used was:
set vList=;
set vDelimiter=CHR(13);
for i = 1 to NoOfFields('FACT')
let vFieldName = FieldName($(i), 'FACT');
let vList = '$(vList)' & $(vDelimiter) & '$(vFieldName)';
next i
TMP:
load * inline [
COLUMN_NAME
$(vList)
];
COLUMNS:
noconcatenate
load COLUMN_NAME
resident TMP
order by COLUMN_NAME asc;
drop table TMP;
Glad you figured it out. However, Your initial question was very generic. Not knowing your full requirement we could not produce exact solution hence provided possible solutions. Please Close the thread marking correct/helpful responses accordingly.
I like this recursive way of doing this with a variable referencing itself in the for loop. I would have probably looped through concatenating onto a table with each field name, but this seems much more efficient. Thanks!