Sometime a very simple task becomes challenging for a developer. A friend of mine, who is a talented database developer, asked me that “He needs to sort his query output rows (as we normally do) but he need to push NULL values at the end”. To be very frank, first I laughed at his question as I thought it’s a simple ORDER BY clause case, but when I tried it, I failed in first attempt ;).
Anyhow, here is a simple solution of sorting any column in ascending order but with NULL at the end.
-- Create temporary-- Insert rowsSELECT 1,'FirstRec','2001-07-01 00:00:00'---- Sort by INT column "RecID"--- Sort by VARCHAR column "RecDesc"--- Sort by DATETIME column "RecDate"-- Drop table when not required