Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Dynamic Field Name in Load Script

Hi I have a question,

I have to data source, let's say.

SourceA

SourceA has field like this,

W1     W2     W3     until ........................... W100

........

I want to load data from SourceA without naming each field one by one

is it possible to loop the field name

So it will be

Load

     Loop var from 1 to 100

     W+var

FROM.... 

7 Replies
sunny_talwar

May be try it with RowNo() or RecNo():

LOAD W & RowNo() as SourceA

sunny_talwar

Capture.PNG

Clever_Anjos
Employee
Employee

table:

load null() as n AutoGenerate 0;

for i = 1 to 100

Concatenate(table)

  LOAD

  'W$(i)' as W$(i)  // Remove quotes when loading from your source

   autogenerate 1;

next

drop Field n;

cwolf
Creator III
Creator III

Create a variable with the fieldnames:

set vFieldNames='';

for i=1 to 100

  let vFieldNames='$(vFieldNames)' & 'W$(i)' & if($(i)<100,',');

next i;

LOAD

$(vFieldNames)

From ...

maxgro
MVP
MVP

load Concat(f, ', ', id) as f;

load recno() as id, 'w' & recno() as f AutoGenerate 100;

let v=peek('f');

table:

load  $(v)

From somefile;

Not applicable
Author

what is this load null() ... autogenerate and drop Field magic ? .. without it the script is a whole Error?

Please explain...

Thank you!

Clever_Anjos
Employee
Employee

The purpose is to create a "stub" table so "Concatenate (table)" would not fail in the very first loop step