请求排查以下iif表达式代码的错误:iif([INLotSerialStatus.LotSerialNbr]=NULL,...)
Hey there, let's break down the problems in your IIF expression and get it fixed:
First, let's list out the key problems with your current code:
Wrong way to check for NULL
In almost all database/expression languages, you can't use= NULLto test if a value is null. Null represents an unknown value, so any equality comparison with it won't work as expected. You need to useIS NULLinstead.Mismatched parentheses & syntax mistakes
Your expression has bracket issues that will make it fail to run:- The
Left()function is missing a closing parenthesis. You haveLeft([INLotSerialStatus.LotSerialNbr], InStr([INLotSerialStatus.LotSerialNbr], '*')but need to add a)at the end of that call. - There's an extra opening parenthesis before
Left()that shouldn't be there, and the entire IIF function is missing a final closing parenthesis to wrap up all arguments.
- The
Logical error with null handling
If[INLotSerialStatus.LotSerialNbr]is null, trying to runLeft()orInStr()on it will throw an error—you can't perform string operations on a null value. It looks like you probably flipped your logic: you likely want to run the substring operation when the value isn't null, and return 'False' when it is null.
Here's a fixed version that aligns with what I assume your intended logic is (return the part of the string before the first '*' when the value exists, else return 'False'):
IIf([INLotSerialStatus.LotSerialNbr] IS NOT NULL, Left([INLotSerialStatus.LotSerialNbr], InStr([INLotSerialStatus.LotSerialNbr], '*') - 1), 'False')
A quick note: I added -1 to the InStr() result because without it, your substring would include the '' character itself. Feel free to remove that if your original goal was to include the '' in the output.
内容的提问来源于stack exchange,提问作者Japsidoo

