SQL Server xQuery returns NULL instead of empty

So in this example, I'm trying to return NULL instead of the empty nvarchar for element2 and element3. It seems that I can not find the answer to this anywhere, or if it is possible. I know that I can check .exists () with nullif of Case / When, but I would prefer not to do this check for performance.

  WqlEventQuery query = new WqlEventQuery ();
         query.EventClassName = "__InstanceCreationEvent";
         query.Condition = "TargetInstance ISA 'Win32_NTLogEvent'";
         query.GroupWithinInterval = new TimeSpan (0, 0, 10);
         System.Collections.Specialized.StringCollection collection =
             new System.Collections.Specialized.StringCollection ();
         collection.Add ("TargetInstance.SourceName");
         query.GroupByPropertyList = collection;
         query.HavingCondition = "NumberOfEvents> 25";
+3
source share
1 answer

I'm not sure what language you are writing your question in, but SQL Server has a NullIf(val, CheckValue) . If you can include this in sql, you will be redirected to the server, which should do the trick:

  Select NullIf(element2, '') 

returns null if element2 is equal to an empty string ('')

+3
source

All Articles