Why objects property value comparison does not check for nothing - vb.net

I am using Entity Framwork and have an Entity Customer with a property of:
CustomerStatus(possible values NULL, 0, 1)
I had code that read
If Not Customer.CustomerStatus = 1 Then
' I want this to execute when Customer.CustomerStatus Is NULL or 0
'Do This
End If
However I noticed that this code does not get executed when Customer.CustomerStatus Is Nothing.
Is this correct for all objects or am I doing soemthing wrong?

Your CustomerStatus is a Nullable(int). This means it can be NULL (it doesn't have a value) or it can be any other Int.
Comparing NULL to 1 returns false. If you want the test to pass one NULL and 1 you could use Customer.CustomerStatus = 1 Or (Not Customer.CustomerStatus.HasValue)

Related

How to return empty array in a case block?

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[])

When nullable integer got null value not executing the command

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"))

Error maxClauseCount searching if certain property is null or not null

When I try to search with Lucene in Alfresco if certain property is not null:
myProperty IS NOT NULL;
or is null:
myProperty IS NULL;
I have this error:
org.apache.lucene.search.BooleanQuery$TooManyClauses - maxClauseCount is set to 10000
This is my query:
SELECT D.cmis:name, D.cmis:objectId, D.cmis:creationDate, R.regxun:numReg, R.regxun:numInterno FROM cmis:document AS D JOIN regxun:contextoRegistroBase AS R ON D.cmis:objectId = R.cmis:objectId WHERE D.cmis:creationDate >= TIMESTAMP '2016-02-18T00:00:00.000Z' AND D.cmis:creationDate < TIMESTAMP '2016-02-19T00:00:00.000Z' AND R.regxun:ambitoDoc='prrubuh' AND R.regxun:numReg IS NOT NULL
Any alternative?
Increase the lucene.query.maxClauses in the alfresco-global.properties to a higher number than 10000.
Like:
lucene.query.maxClauses=100000
But I wouldn't keep it that high, just try to leave the IS NOT NULL statement, which creates a lot of OR clauses in the database query.
For example what you could do is create a rule or behaviour which fill the custom property with a special value (like 'empty') and then search on that.

How can i use_weighted_increment for null data with mdx query

When I try to update cube data with use_weighted_increment, sometimes its giving error for null data.
Is there any thing like slq's isnull()?
Or how can I update empty cell with weighted_increment?
UPDATE [Quota]
SET (
[Dimension1].[Dim1 Attribute1].[Attribute1 Dim1].&[1], //AG1
[DataVersion].[Version].&[1], //Quota
[Dimension2].[Dim2 Parent Member].&[1], //Product 1
[Dimension3].[Dim3 Parent Member].&[-1], //Undefined
[Dimension4].[Dim4 Parent Member].&[-1], //Undefined
[Dimension5].[Dim5 Parent Member].&[-1], //Undefined
[Measures].[Amount Implicit]
) = 6000
USE_WEIGHTED_INCREMENT
0 can be treated like null in MDX.
Therefore you can use "= 0" to test if null.
In this article (http://sqlblog.com/blogs/mosha/archive/2005/06/30/how-to-check-if-cell-is-empty-in-mdx.aspx) by Mosha Pasumansky (one of the creators of mdx) he says that the following:
The first one
IIF(b = 0, NULL, a/b)
Is actually the most correct one.

SQL DB2 - conditional logic in WHERE clause

I need to pull back records based on a location ID, but I've got two fields that MAY contain the incoming criteria....
something like this
SELECT * FROM tbl
WHERE myVar = locationID
IF LocationID = 0
myVar = location2ID
this is a 'logical' example...
I think I can do
WHERE myVar = CASE WHEN locationID = 0 THEN location2ID ELSE locationID END
although I've read that CASE in a WHERE clause should be avoided...? why? or is this OK?
- either way it FAILS
WHERE CASE WHEN locationID=0 THEN location2ID=myVAr ELSE locationID=myVar END
also FAILS
thx
Sorry for the confusion lads - didn't mean to be "ambiguous" - looks like #2 will do what I want - but for the clarification requested here is the issue...
the table stores TWO locations, let's call then CURRENT_LOC and ORIGINAL_LOC... in most cases these will BOTH have data, but in some cases the 'thing' hasn't moved... so the CURRENT_LOC is '0'. MY issue is I'll be passing in a LOCATION ID, I want the records where CURRENT_LOC matches OR if the the CURRENT_LOC=0 then I ALSO want the ORIGINAL_LOC... where that matches...
does that help the discussion? I hope.
WHERE myVar = COALESCE(NULLIF(locationID, 0), location2ID)
Alternatively,
WHERE (
(locationID <> 0 AND myVar = locationID)
OR
(locationID = 0 AND myVar = location2ID)
)