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: 
bharath28
Creator
Creator

Conditional concatenation

Hi All,

Hi All,

I want to concatenate the 2nd table to 1st table, only when 1st table is already loaded, otherwise don't concatenate.

Script-->

IF vFlag = 1 then   

    Table1:

    load...;

ENDIF

If NoOfRows('Table1') > 0

        Set vConcatenate = CONCATENATE(Table1);

           

ELSE

                Set vConcatenate = ;

ENDIF 

$(vConcatenate)

Table2:

load...;

The issue is the dollar expansion $(vConcatenate) is enabling red lines in the below load script. How to avoid this and write a clean code.

1 Solution

Accepted Solutions
Anonymous
Not applicable

That is a cosmetic bug in the syntax checker, so you will just have to live with it.

View solution in original post

8 Replies
Anonymous
Not applicable

That is a cosmetic bug in the syntax checker, so you will just have to live with it.

sunny_talwar

I don't think there is a way to avoid those red lines when you are using a variable. May be you can do something like this:

IF vFlag = 1 then  

    Table1:

    load...;

     Concatenate(Table1)

     load...;

ELSE

     Table2:

     load....;

ENDIF

Kushal_Chawda

try

IF vFlag = 1 then  

    Table1:

    load..

   From Table1;

ENDIF

IF NoOfRows('Table1') > 0 then


concatenate(Table1)

load...

From Table2;

ENDIF


santiago_respane
Specialist
Specialist

Hi Bharath,

the only time i had to do that it wasnt a complex loading load sentence so i solved it with no variables, the bad thing about it is that the load sentence must be added twice and its not a good practice.

Hope it helps!

Kidenst regards,

LOAD * INLINE [
Col1,Col2
345,dfg
456,fgh ]
;
If (NoOfRows('Table1') > 0) THEN
     CONCATENATE(Table1)
     Table2:
     
LOAD * INLINE [
      Col1,Col2
      123,asd
      234,sdf  ]
;
ELSE
     
NOCONCATENATE
      Table2:
     
LOAD * INLINE [
      Col1,Col2
      654,eqweq ]
;
ENDIF

Peter_Cammaert
Partner - Champion III
Partner - Champion III

If you use the code as shown in your OP, you will get run-time errors as well; the CONCATENATE (...) keyword should go after the table name, not before.

Or you can omit the Table2: label before the last LOAD and change the IF-THEN-ENDIF into:

If NoOfRows('Table1') > 0

   Set vConcatenate = CONCATENATE(Table1);

ELSE

   Set vConcatenate = Table2:;

ENDIF

sunny_talwar

Peter I think I have seen Join/concatenate/keep to work before the table name as well. So something like this is what I have seen before:

Join(TableName)

Table1

LOAD ....

Concatenate(TableName)

Table2

LOAD ....

bharath28
Creator
Creator
Author

@Sunny, you are right. The concatenate keyword works either above or below the table name.

bharath28
Creator
Creator
Author

Thanks Peter. Your solution is nice, however the syntax red lines seems cannot be avoided.