How can I display which column has the latest date?
My employers often have me run reports directly off of our databases, and I seem to have run into a snag on one of them. I need to find out whether a claim is logged in or out of our system and we have 2 different columns (Log_In_Date and Log_MAIL_Date) in the table that tracks our claims (Claimlog) for part of a report that I am generating.
I originally used a case statement:
This worked for the most part, but I've run into some duplicate results with both "In" and "Out" returns. After doing some research, I adjusted the query to:
to account for null values. Unfortunately, I'm still getting the return of both In and Out for the same entries:
LOG_DEALER LOG_CLAIM LoggedInStatus
04839 239831 In
04839 239831 Out
01563-5 387468 Out
I've tried replacing COALESCE
with NOTNULL
and rewriting the select statement as:
Still no luck getting the results. Does anyone have any suggestions on how to properly query this?
According to the sample data and query, LOG_MAIL_DATE has the constraint NOT NULL. This is preventing the insert of the following values:
INSERT INTO #mytable VALUES ('04839', '2018-06-07 00:00:00',681150,1, 239381,2, NULL, 1, 'C',NULL,NULL,NULL,'2018-04-11 00:00:00',2785317);
But, for your question, you can always add a where clause like below:
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.