AnsweredAssumed Answered

SQL Query: How if statements in picalc expr should be formatted?

Question asked by Namsraijav on Jan 3, 2015
Latest reply on Dec 6, 2016 by avanfosson
Branched to a new discussion

Hi everyone,

 

I'm trying to run the following Performance Equation in PI SQL Commander, and I'm getting syntax error:

======

if 'Tag1'="RUNNING" or 'Tag2'="RUNNING" then (TagVal('Tag3')+TagVal('Tag4'))/2 else TagVal('Tag3') else if  'Tag4'>0 then TagVal('Tag4') else 0

======

 

The query I used is:

======

SELECT expr, time, value FROM piarchive..picalc WHERE expr = 'if ''Tag1''="RUNNING" or ''Tag2''="RUNNING" then (TagVal(''Tag3'')+TagVal(''Tag4''))/2 else TagVal(''Tag3'') else if  ''Tag4''>0 then TagVal(''Tag4'') else 0'

      AND time = '*'

======

 

The syntax error I'm getting is: "[PI SDK] PI PE syntax error in Expression. [-12301] Performance Equation parsing error"

 

Below simple query with simple PE works just fine.

======

  SELECT expr, time, value FROM piarchive..picalc WHERE expr = 'TagVal(''sinusoid'') / 2'

      AND time = '*'

======

 

I need your support guys.

Any advise is greatly appreciated. :-)

Outcomes