Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to ADD new Column in table wich the value of the column is the name of the table?

Good Morning Community,

I have many tables (source MS SQL) they have the same columns structure

Load a,b,c from Table_1;

..

Load a,b,c from Table_X;

..

Load a,b,c from Table_150;


I wana befor Loading each table ,creating new column ID that equal the number of the table TABLE_?


Résultat:

IDabc
1
..
150


1 Solution

Accepted Solutions
andrei_delta
Partner - Creator III
Partner - Creator III

hello,

i think you can use a command that reads the name of the tables from ms sql (select  * from schema_tables i think)and puts them into one field;

then you read that field into a qlikview table;

then let vNoOfRows= NoOfRows('TableName');

MergedTables:

load * inline [

ID

];

then  for i=0 to$( vNoOfRows)-1

let vTableName=peek('the name of the field',i,'the name of the table that contains the field');

let vTableID=replace(vTableName,'Table_','');

concatenate(MergedTables)

Load

*,

$(vTableID) as ID

From $(vTableName);

next i;

Something like that...

I hope it helps,

Andrei

View solution in original post

6 Replies
suryaa30
Creator II
Creator II

Load

a,

b,

c,

'1' as ID

from Table1;

Load

a,

b,

c,

'2' as ID

from Table2;

if the table count is less do it manually. otherwise better to create a loop.

richard_chilvers
Specialist
Specialist

How about:

LOAD a,b,c, 'Table_1' AS ID FROM Table_1;

LOAD a,b,c, 'Table_2' AS ID FROM Table_2;

etc.

If you just want 1,2 etc. in the ID field, you can use the appropriate string function.

HTH

andrei_delta
Partner - Creator III
Partner - Creator III

hello,

i think you can use a command that reads the name of the tables from ms sql (select  * from schema_tables i think)and puts them into one field;

then you read that field into a qlikview table;

then let vNoOfRows= NoOfRows('TableName');

MergedTables:

load * inline [

ID

];

then  for i=0 to$( vNoOfRows)-1

let vTableName=peek('the name of the field',i,'the name of the table that contains the field');

let vTableID=replace(vTableName,'Table_','');

concatenate(MergedTables)

Load

*,

$(vTableID) as ID

From $(vTableName);

next i;

Something like that...

I hope it helps,

Andrei

Not applicable
Author

Thank you Surya

Not applicable
Author

Thank you

Not applicable
Author

thank you