Search code examples
sql-servercrystal-reports

Crystal Reports if function combined with a val function


I feel very stupid but I cannot see what is going on.

The field U22 has a varchar field. So i'm doing the following in term of logic

If U22 IS NULL OR empty then take the numbers out of {ENTREPRISES.U22}

IF ISNULL({ENTREPRISES.U22}) OR {ENTREPRISES.U22} = '' THEN '' 
 ELSE VAL({ENTREPRISES.U22})  

Everytime I'm saving this , I have this error

enter image description here

Type a string

I've done the following

If I only put this VAL({ENTREPRISES.U22}, things are fine, if I put the other part IF ISNULL({ENTREPRISES.U22}) OR {ENTREPRISES.U22} = '' THEN '' things are fine too.

Does anyone know why?

Thanks


Solution

  • you cannot mix data types in an If Then Statement .. try this

    IF ISNULL({ENTREPRISES.U22}) OR {ENTREPRISES.U22} = '' THEN '' 
     ELSE {ENTREPRISES.U22}
    

    or

    IF ISNULL({ENTREPRISES.U22}) OR {ENTREPRISES.U22} = '' THEN 0 
     ELSE VAL({ENTREPRISES.U22})