因此,在这个例子中,我试图返回一个空nvarchar的一个NULL,而不是为元素1和元素3。我似乎无法找到一个答案,这在任何地方,或者如果它甚至有可能。我知道我可以检查.exists()与案例/当一个NULLIF,但我宁愿不作出这样的检查,为了表现。
WqlEventQuery查询=新WqlEventQuery(); query.EventClassName =__InstanceCreationEvent; query.Condition =TargetInstance ISA'Win32_NTLogEvent'; query.GroupWithinInterval =新时间跨度(0,0,10); System.Collections.Specialized.StringCollection集合= 新System.Collections.Specialized.StringCollection(); collection.Add(TargetInstance.SourceName); query.GroupByPropertyList =收集; query.HavingCondition =NumberOfEvents> 25;
解决方案
我不知道你是从你的问题写什么语言,但SQL Server有一个 NULLIF(VAL,校验值)
功能。如果你可以包括在SQL传递给了应该做的伎俩服务器:
选择NULLIF(元素1,'')
将返回一个空如果元素1等于空字符串('')
So in this example I'm trying to return a NULL instead of an empty nvarchar for element2 and element3. I can't seem to find an answer to this anywhere, or if it's even possible. I know I can check .exists() with a nullif of Case/When, but I'd rather not make that check for the sake of 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";
解决方案
I'm not sure what language you are writing in from your question, but SQL Server has a NullIf(val, CheckValue)
function. If you can include that in the sql you pass to the server that should do the trick:
Select NullIf(element2, '')
will return a null if element2 is equal to an empty string ('')
上一篇:我怎么能prevent使用一个窗口服务正在创建一个文件夹?创建一个、文件夹、窗口、我怎么能
下一篇:JsonConvert.DeserializeObject和" D"包装在WCF装在、DeserializeObject、JsonConvert、WCF