April 6, 2011 at 6:19 pm
Using SQL 2000
I have an orders table and need to most recent order for a customer based on the Update Date first and if null then the Create Date (never Null)
Then I need to join that row to the customer table and display the customer information with the most recent order all in a single row.
I can do it with a single date but can't figure out how to do it when there are 2 date fields to evaluate....
Help is much appreciated.
Thanks in advance.
April 7, 2011 at 2:41 pm
How about something like:
SELECT Top 1 OrderNumber
FROM Orders
ORDER BY CASE WHEN UpdateDate IS NULL THEN CreateDate ELSE UpdateDate END DESC
or
SELECT Top 1 OrderNumber
FROM Orders
ORDER BY ISNULL(UpdateDate, CreateDate) DESC
April 7, 2011 at 3:26 pm
Thanks!
Heres what I ended up with before I say your reply.
, IsNull(dbo.drug_eligibility.UpdateDate, CreateDate) AS SortDate
its working. Thnaks again!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply