Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
grant_S
Contributor

how to add suffix to each field?

I have a table t1 as below, I want to add number 2 to each field, such as  ID changed to ID2, 

currently I did it manually but need much time to do it. whether there is a easy way to do that, such as :  load * as *&2 ?(actually *&2 cannot work) .


t1:
load * Inline [
ID,name,age
1,grant,22
2,sunny,33
];

T2:
NoConcatenate load
ID as ID2,
name as name2,
age as age2 Resident t1;

drop table t1;

1 Solution

Accepted Solutions
Or
MVP

 If you're OK with a prefix instead, you can use the Qualify statement to prefix the table name to each field (Note: You should unqualify any key fields). The below code will prefix all fields in T2 with e.g. T2.ID.

Alternatively, for suffixes, you can use Rename Field later in your script. You can set up an Excel field where you copy the list of fields to column A, append a '2' to the end of each in column B, and then have an Excel formula that generates the Qlik syntax Rename Field A1 to B1; and copy those en-masse to your Qlik script.

Finally, you could probably also achieve this with a Qlik loop, loosely written as pseudocode (For specific syntax and examples, you can search for Qlik FOR loops):

For each Field in T2

Let Variable = FieldName & '2';

Rename Field to [$(Variable)]

Next Field

 

 

t1:
load * Inline [
ID,name,age
1,grant,22
2,sunny,33
];

Qualify *;

T2:
NoConcatenate load
ID as ID2,
name as name2,
age as age2 Resident t1;

 

Unqualify *;

drop table t1;

View solution in original post

1 Reply
Or
MVP

 If you're OK with a prefix instead, you can use the Qualify statement to prefix the table name to each field (Note: You should unqualify any key fields). The below code will prefix all fields in T2 with e.g. T2.ID.

Alternatively, for suffixes, you can use Rename Field later in your script. You can set up an Excel field where you copy the list of fields to column A, append a '2' to the end of each in column B, and then have an Excel formula that generates the Qlik syntax Rename Field A1 to B1; and copy those en-masse to your Qlik script.

Finally, you could probably also achieve this with a Qlik loop, loosely written as pseudocode (For specific syntax and examples, you can search for Qlik FOR loops):

For each Field in T2

Let Variable = FieldName & '2';

Rename Field to [$(Variable)]

Next Field

 

 

t1:
load * Inline [
ID,name,age
1,grant,22
2,sunny,33
];

Qualify *;

T2:
NoConcatenate load
ID as ID2,
name as name2,
age as age2 Resident t1;

 

Unqualify *;

drop table t1;