Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
eduardo_dimperio
Specialist II
Specialist II

Help with If Statement

Hi everyone,

Im trying to use some if's, i already did many times before and for that reason i dont know why this error happen. When  I run the code its expect "Then". For that reason i need some help to understand what im doing wrong.

for a=1 to 2

LET vCOD_CONTROLE = $(a);

If ($(a)=1,vPath='MI_csv',vPath='Ultragaz QVD')

RS_SYSTEM:

load

  $(vCOD_CONTROLE) AS COD_CONTROLE,

    $(vCOD_CONTROLE)&'|'&OID_SYSTEM AS OID_SYSTEM,

    $(vCOD_CONTROLE)&'|'&OID_GROUP AS OID_GROUP,

    NAME_SYSTEM,

    SSN_REMOTE_SYSTEM,

    MIN_REMOTE_SYSTEM,

    NUM_CONCENTRATORS,

    NUM_PORTS_CONCENTRATORS,

    CUT_RELIG_FLAG,

    ADDRESS_SYSTEM,

    ADDRESS_NUMBER_SYSTEM,

    NEIGHB_SYSTEM,

    CITY_SYSTEM,

    UF_SYSTEM,

    CEP_SYSTEM,

    STATUS,

  $(vCOD_CONTROLE)&'|'&ID_SYSTEM_TYPE AS ID_SYSTEM_TYPE

    FROM [lib://$(vPath)/RS_SYSTEM.qvd] (QVD);

If($(a)=2,store RS_SYSTEM into [lib://MI Ultragaz/RS_SYSTEM.qvd]);

  Next

   

    exit script

Thank's

7 Replies
m_woolf
Master II
Master II

If  $(a)=1 then

     vPath='MI_csv';

else

     vPath='Ultragaz QVD';

endif

Nicole-Smith

IF statements used in script are written a bit differently than if on a chart.  If I'm understanding what you're trying to do here, I think this is what you need written differently (lines 3 and 26-28):

FOR a=1 TO 2

  LET vCOD_CONTROLE = $(a);

  LET vPath = If($(a)=1,'MI_csv','Ultragaz QVD');

  RS_SYSTEM:

  load

  $(vCOD_CONTROLE) AS COD_CONTROLE,

  $(vCOD_CONTROLE)&'|'&OID_SYSTEM AS OID_SYSTEM,

  $(vCOD_CONTROLE)&'|'&OID_GROUP AS OID_GROUP,

  NAME_SYSTEM,

  SSN_REMOTE_SYSTEM,

  MIN_REMOTE_SYSTEM,

  NUM_CONCENTRATORS,

  NUM_PORTS_CONCENTRATORS,

  CUT_RELIG_FLAG,

  ADDRESS_SYSTEM,

  ADDRESS_NUMBER_SYSTEM,

  NEIGHB_SYSTEM,

  CITY_SYSTEM,

  UF_SYSTEM,

  CEP_SYSTEM,

  STATUS,

  $(vCOD_CONTROLE)&'|'&ID_SYSTEM_TYPE AS ID_SYSTEM_TYPE

  FROM [lib://$(vPath)/RS_SYSTEM.qvd] (QVD);

  IF $(a)=2 THEN

  store RS_SYSTEM into [lib://MI Ultragaz/RS_SYSTEM.qvd];

  ENDIF

Next

 

exit script

eduardo_dimperio
Specialist II
Specialist II
Author

Hi mw, this way that you writed works and i use, but i want to kno why the simplificated version doesn't.

eduardo_dimperio
Specialist II
Specialist II
Author

Hi Nicole,

I already did this "If" other times and works. here a example that works in other place in my code

Exclude_Meter:

LOAD

DISTINCT

OID_METER,

VALOR,

If((PEEK(VALOR)- VALOR)=0,OID_METER) AS EXCLUIR,

DATA,

TEMPO

RESIDENT Corrige_Medidor

ORDER BY OID_METER,DATA,TEMPO DESC ;

This "If" works and have the same structure of the other.

Anonymous
Not applicable

Eduardo,

You're mixing two different IFs.

1. What you use in your latest example, is a conditional function
if(condition, expression if true, expression if false)

2. The solution you needed in your opening question is the script control statement

IF ... THEN ... ELSE ... ENDIF.

You cannot replace one with the other.

eduardo_dimperio
Specialist II
Specialist II
Author

Hum.. nice, but why the conditional function doesn't apply in this case?

Cause i think if(condition, expression if true, expression if false) applies to it.

if condition           $(a)=1,

expression if true vPath='MI_csv',

expression if false vPath='Ultragaz QVD')

and thank you for your time

Anonymous
Not applicable

You still can use conditional function if you prefer.  Here is a syntax that should work:

LET vPath = If ($(a)=1, 'MI_csv', 'Ultragaz QVD');