Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
raZor
Contributor III
Contributor III

Rename all the columns in a table

Hi Qlikers,

I have a table like-

 

 

Lib connect to 'Data Source'

Load

Source1_id,

Source1_name,

Source1_address,

Source1_date;

[Table]:

Select *

From 'data';

 

I want to remove Source1_ from all the fields.

Does this have any solution?

 

Kind Regards

 

Labels (2)
1 Solution

Accepted Solutions
maxgro
MVP
MVP

 

T25:
Load * inline [
Source1_id, Source1_name, Source1_address, Source1_date
1,2,3,4
];

for j=1 to NoOfFields('T25')

    let vFieldName = FieldName($(j),'T25');
    let vMatch = wildmatch('$(vFieldName)', 'Source1_*');
    TRACE $(vFieldName) $(vMatch);

    if $(vMatch) then
        LET vNewFieldName = RIGHT('$(vFieldName)', LEN('$(vFieldName)') - LEN('Source1_') );
        TRACE 'RENAME $(vFieldName)' '$(vNewFieldName)';
        RENAME Field [$(vFieldName)] TO [$(vNewFieldName)];
    ENDIF

NEXT

View solution in original post

3 Replies
maxgro
MVP
MVP

 

T25:
Load * inline [
Source1_id, Source1_name, Source1_address, Source1_date
1,2,3,4
];

for j=1 to NoOfFields('T25')

    let vFieldName = FieldName($(j),'T25');
    let vMatch = wildmatch('$(vFieldName)', 'Source1_*');
    TRACE $(vFieldName) $(vMatch);

    if $(vMatch) then
        LET vNewFieldName = RIGHT('$(vFieldName)', LEN('$(vFieldName)') - LEN('Source1_') );
        TRACE 'RENAME $(vFieldName)' '$(vNewFieldName)';
        RENAME Field [$(vFieldName)] TO [$(vNewFieldName)];
    ENDIF

NEXT

raZor
Contributor III
Contributor III
Author

Thank you so much Mxgro, it worked the way I wanted.

Now, can I add 'S1_' as prefix on all renamed fields?

Like, S1_id

Kind Regards

maxgro
MVP
MVP

try with

LET vNewFieldName = 'S1_' & RIGHT('$(vFieldName)', LEN('$(vFieldName)') - LEN('Source1_') );