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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

if statement with special characters

Hello,

i not unterstand why the folling if statement produce a 'no' ,because a special character '-' more than  space character like '  '?

if( '-' > '  ','yes','no')

result : no

Have anyone an idea what operation QlikView do in the bakground ?

10 Replies
sushil353
Master II
Master II

hi,

Use this:

=if( ord('-') > ord(' '),'yes','no')

HTH

Sushil

Not applicable
Author

Yes this works, but is this behaviour when i not use ord function normal in QlikView that '-' ist not more than '  ' ?

sushil353
Master II
Master II

- and ' ' is treated as character and you can not do greater than or less than of some character values... for this to happen you need to convert the chartacter value to corresponding numerical value..

that is why i have used ord() function.

Regards,

Sushil

gaurav2017
Creator II
Creator II

Dear,

please close the issues by marking the correct answer when the solution has been given as desired.

Regards

Gaurav

peschu123
Partner - Creator III
Partner - Creator III

Hi pkrolicki,

I assume there is another value in the field...

I tried the following and the result is always "YES".

tmp:

LOAD * INLINE [test,test2

-,

'-',''];

TEST:

LOAD

//IF(test > test2,'YES','NO') AS bla  // --> YES

IF(test > '','YES','NO') AS bla  // --> YES

//IF(test > null(),'YES','NO') AS bla // --> NO

RESIDENT tmp;

Perhaps there is a difference between ' ' and '' ... the blank between the quotes. I don't know if you have a blank in your example. You could check this.

Hope it helps!

- PS -

Not applicable
Author

yes a blank is between the ' ' . I think the comparison beetween '-' and  '  ' is for QV unlogical.

peschu123
Partner - Creator III
Partner - Creator III

Or a blank is > than '-' for QV  ...is it necessary to have fields with a blank? In some cases this can be very confusing...? I think simple comparing(greater as..)of chars is unlogical at all..ok with abc you could do the ranking based on the alphabet etc. . And that a char is greater than no char could be logical too. But "minus" vs. "blank" ....

Perhaps the function chr() can help you in some situations...

flipside
Partner - Specialist II
Partner - Specialist II

Could be QV is trying to resolve the '-' as a numerical negative rather than just hyphen. Consider this equation ...

=if('-0.6'>'-0.5',1,2) ... which returns 2.

Textually  '-0.6' comes after  '-0.5' but QV resolves the values to numbers and correctly calculates the numerical comparison where -0.6 is less than -0.5. If '-' is resolved as a number and the other value is text, they cannot be compared and cannot be true, therefore false.

Think only Qliktech could confirm.

flipside

Not applicable
Author

Yes it could be so but why the result for the following  :

1:

Load * Inline

[a

'-'

' , '

' ' '

' " '

'{']

;

2:

Load

if( a > ' ','yes','no'),

* resident 1;

is : no

     no    

     yes

     yes

     yes

? It seems to be a logic behind it ...