Start a new topic

IF Statement in SemQL for SQL Server

Is the IF function available in SemQL for SQL Server?  I now the CASE statement is and that is what I've used in the past.  I'm having to replicate a complicated If statement from excel into semarchy.  Using an If statement would simplify the syntax over a CASE statement.  The CASE statement isn't documented as a function so I was wondering if the IF statement was also available but not documented.  If so, what is the syntax?


Thanks,

Matt


My use case is that we are replacing a Google Sheet that is used to request a material creation. One of the fields in the sheet is "Status".  The formula on that cell is pretty complex and I need to replicate it in Semarchy.  Below is the example formula.  A CASE statement would be extremely complex.  Would this be a good example to use a SQL HOOK?


=IF(OR(L2<>"",M2<>"",N2<>"",O2<>"",P2<>"",Q2<>"",R2<>"",S2<>"",T2<>"",U2<>"",V2<>"",W2<>"",X2<>"",Y2<>"",Z2<>""),IF(OR(AND(OR(M2="Label",M2="Shrink Band",M2="Other Material",M2="Sticker"),L2<>"",O2<>"",P2<>"",Q2<>"",R2<>"",S2<>""),AND(OR(M2="FG SKU",M2="WIP SKU"),L2<>"",O2<>"",P2<>"",Q2<>"",R2<>"",S2<>"",W2<>"",X2<>"")),IF(S2="New","Complete",IF(T2<>"","Complete","Incomplete")),"Incomplete"),"")


P

Hello Matthew,


IF statement is not present but you can use CASE WHEN instead of IF which helps you to achieve your use case, also CASE function is present in the documentation.

For sample-


CASE
    WHEN condition_1 THEN result_1
    ...
    WHEN condition_n THEN result_n
    [ELSE default_result]
END
Login to post a comment