I have problems with a null check on a user defined member property in mdx.
The property is of type datetime in cube. If I check the value in mdx, it will return the date or null if no value was provided.
MEMBER [Measures].[TheValue] as MyMember.Properties("MyProperty") //returns (null) or date, e.g. 01.04.2015
However I cannot null-check the value.
MEMBER [Measures].[TheValueExists] as IIF(ISEMPTY(MyMember.Properties("MyProperty")), false, true)
always evaluates to true, which is wrong, and the same with 'is null' always returns an error. Would be thankful for any hints.
The thing that made it work was adding the typed-overload:
MEMBER [Measures].[TheValueExists] as IIF(ISEMPTY([MyMember.Properties("MyProperty", typed)),
false, true)
Related
working on a trigger in Postgres. Currently running into an issue where I'm trying to set a value as either an empty array or an array with just the one NEW value, depending on if there is a NEW value or not:
project_ids =
CASE NEW.project_tracking_id
WHEN null THEN ARRAY
ELSE ARRAY[NEW.project_tracking_id]
END
"Set project_ids to either [] (if null) or [NEW.project_tracking_id]"
The else block works as expected and will store that new value as the first element in a new array. The WHEN null THEN ARRAY part does not work for me though. It just adds null to the array, producing [null].
How do I specify that it should just be an empty array in that case? Not sure if this helps, but my sequelize type for that field is:
type: Sequelize.ARRAY(Sequelize.STRING),
defaultValue: [],
project_ids =
CASE NEW.project_tracking_id
WHEN null THEN ARRAY[]::XXX[] //XXX is the type of the array.
ELSE ARRAY[NEW.project_tracking_id]
END
The problem is that your CASE expression implicitly compares NEW.project_tracking_id = NULL, which is never true, even if the left side is NULL. Use the other form of CASE:
CASE WHEN NEW.project_tracking_id IS NULL
THEN ARRAY[]::integer[]
ELSE ARRAY[NEW.project_tracking_id]
END
This assumes that the data type of NEW.project_tracking_id is integer; change the array type if that is not the case.
A shorter version of the above would be
coalesce(NEW.project_tracking_id, ARRAY[]::integer[])
I'm working on a search form based off a single table. I'm working primarily in the query design view. I'd like to have a checkbox on the form so if it is checked (true) it will only return records where the setID is Null. If unchecked (false) it will return all records regardless of if there is a value in setID or not. Looking for a bit of help writing the iif statement (I'm very, very new to this).
source table: Inventory
field: setID
form: frmSearchInventory
form control: ckExcludeSet
iif(Forms!frmSearchInventory!ckExcludeSets = true, Inventory.SetID is Null, Inventory.SetID is not Null)
Close? Also, in the query design view, do I need anything additional in the criteria row? Many thanks!
For a dynamic query, calculate a field that returns SetID or a value in lieu of null: Nz(SetID, "N")
Then criteria under that calculated field:
LIKE IIf(Forms!frmSearchInventory!ckExcludeSets, "N", "*")
An unbound checkbox can be set for triple state. Make sure yours allows only True or False, never Null - set TripleState property to No. Set DefaultValue property to either True or False.
Is it possible to declare a function that only ever returns null? Unfortunately, you cannot write null in the return type section. The return value should be null and not Unit so that it can work with nullable operators.
As also suggested in the comments, Nothing? should be the return type of such a function:
fun alwaysNull(): Nothing? = null
The documentation states:
[...] Another case where you may encounter this type is type inference. The nullable variant of this type, Nothing?, has exactly one possible value, which is null. If you use null to initialize a value of an inferred type and there's no other information that can be used to determine a more specific type, the compiler will infer the Nothing? type:
val x = null // 'x' has type `Nothing?`
val l = listOf(null) // 'l' has type `List<Nothing?>
i have this query as linq:
Dim result = (From c In query _
Where Not bannedCCList.Contains(c.num_reserv) _
Group c By c.code_operation, c.code_type _
Into nbr = Count(CInt(c.Code_bien)), acmp = Sum(CDec(c.TotalAcomp)) _
Select nbr, acmp).ToList
but i get the error:
An object that allows Null must have a value
how i can put acmp=0 if c.TotalAcomp is nothing
i that my query look like:
acmp =IIF(Sum(CDec(c.TotalAcomp)) is nothing,0, Sum(CDec(c.TotalAcomp)) _
but it doesn't work.
try this:
acmp =IIF(Sum(CDec(c.TotalAcomp)) is DBNull.Value,0, Sum(CDec(c.TotalAcomp))
Don´t use IIF. It´s old VB6 garbage, e.g. it evaluates always both sides even if the true-part returns true. Use If instead.
Your check if the variable is Nothing happens at the wrong place. You have to check it inside the Sum function not afterwards.
Also use HasValue and Value properties of nullable types.
In this case you don´t have to cast any of your expression (besides you casted to the wrong type. If your variable is of type Double don´t cast to Decimal).
The following code worked for me:
acmp = Sum(If(Not c.TotalAcomp.HasValue, 0, c.TotalAcomp.Value))
I have VB.Net code which value taking from db and if it is null do some job
While reader.Read
tocken = reader.GetInt16("Tocken_No")
If tocken.HasValue = False Then
TxtPTocken.Text = 1
Else
TxtPTocken.Text = tocken + 1
End If
End While
Else statement working properly but first part not. tocken is nullable short. What I'm missing? Please help
That code doesn't make sense. You're calling GetInt16, which means you're going to get an Int16. Your tocken variable may be type Nullable(Of Short) but you're assigning a value to it so HasValue is ALWAYS going to be True.
Your issue there is that if your database field is NULL then your code is going to throw an exception. Methods like GetIn16 fail if there isn't a value of the expected type available. It's up to you to check for NULL and handle that accordingly:
tocken = If(reader.IsDBNull(reader.GetOrdinal("Tocken_No")),
CType(Nothing, Short?),
reader.GetInt16("Tocken_No"))