Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

cancel
Showing results for 
Search instead for 
Did you mean: 
qvraj123
Creator II
Creator II

whats wrong in this condition

Hi All, Thanks for your time,

I have a load statement something like below

CBDI_DATA:

LOAD

UPPER(TRIM(Short_Server_Name)) AS ShrtServerName

FROM A FILE;

>>

EXAMPLE OF VALUES IN ShrtServerName FROM THE ABOVE LOAD ARE DEV,UAT,PROD,TEST,SAND ETC

>>

IF THE VALUE IN ShrtServerName is DEV THEN I want to do the concatenate like below with a space after the beginning of the first star and a space before the 2nd star something like * DEV * - else part would be same but without spaces

this is giving an error as invalid expression - any suggestions

CBDI_DATA_CONDTION1:

LOAD

if(ShrtServerName= 'DEV', Concat(chr(39) &'*'& ShrtServerName &'*' & chr(39), ',')  ,'NO'   ) AS  ShrtDerived

RESIDENT CBDI_DATA;

DROP TABLE CBDI_DATA;

9 Replies
prma7799
Master III
Master III

Any error you are facing with this expression ?

qvraj123
Creator II
Creator II
Author

invalid expression is the error message for some reason it does not like the IF condition in it if I take out the IF condition the concat works fine

prma7799
Master III
Master III

Can you please share some sample app and expected output.

qvraj123
Creator II
Creator II
Author

HI PM

thanks for your time, attached sample qvw file

jonathandienst
Partner
Partner

Concat() is an aggregation function and it requires a group by clause if any fields are referenced outside of aggregation functions...

This line makes no syntactic sense.

if(ShrtServerName= 'DEV', Concat(chr(39) &'*'& ShrtServerName &'*' & chr(39), ',')  ,'NO'   )


What are you concatenating?

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
qvraj123
Creator II
Creator II
Author

Thank you Jonathan,

The reason I was using an IF condition is I want to check for the value DEV as the concat is different for this

IF(ShrtServerName = 'DEV' THEN

Concat(chr(39) &'* '& ShrtServerName &' *' & chr(39), ',')

ELSE

Concat(chr(39) &'*'& ShrtServerName &'*' & chr(39), ',')

AS DerivedSName

I remember reading concat is an aggregation function - thanks a lot - let me use this with a group by

Thanks again

jasonmomoa
Creator
Creator

Hello qvraj123‌,

You don't even need the Concat function in the script. Just using standard 'concatenation' string operations with '&'. See example below:

CBDI_DATA:

LOAD * Inline [

ShrtServerName

    DEV

    UAT

    PROD

    TEST

    SAND

];


CBDI_DATA_CONDTION1:

LOAD

ShrtServerName,

IF(ShrtServerName= 'DEV',

    '* ' & ShrtServerName & ' *',                  // with spaces for DEV server name

    '*'  & ShrtServerName & '*') as ShrtDerived    // without spaces

RESIDENT CBDI_DATA;

DROP TABLE CBDI_DATA;

The output of this script is:

srvrnm.PNG

I believe this was the behavior you were trying to achieve.

Hope it helps you.

Regards,

qvraj123
Creator II
Creator II
Author

i have to get these values like '* DEV *', '*UAT*' ETC and store them into a variable since I will be using this variable later in a wildmatch like wildmatch(Myfield, vVariable1) - that's the reason for including the single quotes for each word

Thanks a lot

qvraj123
Creator II
Creator II
Author

Thank you Jonathan, this worked with the group by