2017-02-27 71 views
0

我的日期列在sql表中可以为空,所以我使用OData获取该数据,但如果我通过asc命令它,则空值位于所有其他行之前。我想,这一切都他人后desplayed:Odata覆盖行为orderby

1. 31.12.2000 
2. 31.12.2010 
3. null 

是否有可能以某种方式覆盖过滤所以它采取空值可能是DateTime.MaxValue?

回答

1

ANSI标准支持NULLS FIRSTNULLS LAST,但SQL Server没有这些选项。

相反,你可以在ORDER BY使用两个密钥:

order by (case when col is not null then 1 else 2 end), 
     col asc 
+0

不正是我需要的。这里[link](https://msdn.microsoft.com/en-us/library/gg309461(v = crm.7).aspx#BKMK_orderby)就是我使用
'/ AccountSet?命令的例子$ select = Address1_Country ,Address1_City,Name&$ orderby = Address1_Country asc&$ filter =(Address1_Country ne null)and(Address1_City ne null)'。
那么如何更改$ orderby = Address1_Country asc,所以空值会进入队列末尾。 – maximelian1986

+0

由于没有其他建议,我会将其标记为正确的,因为它指出了我的问题的另一个解决方案。不过,我更新了数据库并将null更改为DateTime.MaxValue,因此可以使用OData orderby属性完成排序。 – maximelian1986