Order by not null date : Order by « Query « SQL Server / T-SQL Tutorial






7> CREATE TABLE Orders (
8>      OrderID int NOT NULL ,
9>      CustomerID nchar (5) NULL ,
10>     EmployeeID int NULL ,
11>     OrderDate datetime NULL ,
12>     RequiredDate datetime NULL ,
13>     ShippedDate datetime NULL ,
14>     ShipVia int NULL ,
15>     Freight money NULL DEFAULT (0),
16>     ShipName nvarchar (40) NULL ,
17>     ShipAddress nvarchar (60) NULL ,
18>     ShipCity nvarchar (15) NULL ,
19>     ShipRegion nvarchar (15) NULL ,
20>     ShipPostalCode nvarchar (10) NULL ,
21>     ShipCountry nvarchar (15) NULL
22> )
23> GO

1>
2>    SELECT TOP 5 OrderID, OrderDate
3>    FROM Orders
4>    WHERE OrderDate IS NOT NULL
5>    ORDER BY OrderDate
6> GO
OrderID     OrderDate
----------- -----------------------

(0 rows affected)
1>
2> drop table Orders;
3> GO








1.3.Order by
1.3.1.The expanded syntax of the ORDER BY clause
1.3.2.ORDER BY Clause: ORDER BY {[col_name | col_number [ASC | DESC]]}, ...
1.3.3.Sorting your grouped results with ORDER BY clause.
1.3.4.An ORDER BY clause that sorts by one column in descending sequence
1.3.5.the order criterion may contain more than one column.
1.3.6.An ORDER BY clause that sorts by three columns
1.3.7.An ORDER BY clause that uses an alias
1.3.8.An ORDER BY clause that uses an expression
1.3.9.An ORDER BY clause that uses column positions
1.3.10.Sorting your grouped results by an aggregate.
1.3.11.NULLs Sort Last
1.3.12.order criterion contains any aggregate function.
1.3.13.Order by not null date
1.3.14.Using the TOP keyword with Ordered Results
1.3.15.do our sorting using numeric fields
1.3.16.use CAST function to sort during ordering