I have a table that has (for example) 4 columns.
pk_table_id INT NOT NULLusername VARCHAR(100) NOT NULLstart_date DATETIME NOT NULLend_date DATETIME NULL
My requirement is to return all rows in descending order of end_date – BUT the NULL values must be first, and then descending order of start_date.
I’ve done it in SQL – but could someone assist me with a LINQ version to do this?
This is the SQL query we use:
SELECT [person_employment_id]
, [party_id]
, [employer_name]
, [occupation]
, [telephone]
, [start_date]
, [end_date]
, [person_employment_type_id]
, [person_employment_end_reason_type_id]
, [comments]
, [deleted]
, [create_user]
, [create_date]
, [last_update_user]
, [last_update_date]
, [version]
FROM [dbo].[person_employment]
WHERE ([party_id]=@party_id)
ORDER BY ISNull([end_date],'9999-DEC-31') DESC, [start_date] DESC
For this problem, you could do a null check on the
end_dateand use that result as the ordering. So you don’t need to use the same SQL constructs to achieve this, but rather use one more natural in your language of choice (C# I’m assuming).