I have a date column which has some NULL
. I want to order by the date column ASC, but I need the NULL
s to be at the bottom. How to do it on TSQL?
相关问题
- sql execution latency when assign to a variable
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
相关文章
- Entity Framework 4.3.1 failing to create (/open) a
- How to truncate seconds in TSQL?
- Code for inserting data into SQL Server database u
- Delete Every Alternate Row in SQL
- Linux based PHP install connecting to MsSQL Server
- SQL Azure Reset autoincrement
- How do we alias a Sql Server instance name used in
- Is recursion good in SQL Server?
order by case when col_name is null then 1 else 2 end, col_name asc
did the trick on Oracle. However the same on MS SQL Server pushes the NULL records down leaving non null to be on top of the result set.In standard SQL you can specify where to put nulls:
but T-SQL doesn't comply with the standard here. The order of NULLs depends on whether you sort ascending or descending in T-SQL:
With integers you could simply sort by the negatives:
But this is not possible with dates (or strings for that matter), so you must first sort by is null / is not null and only then by your column:
Or even
Order By IsNull(DateCol,'2525-12-31')