I have a query that return some record, but I need to get whatever the latest tm.detail_notes
on max(tm.timeslip_date)
. Right now I am getting an error. (I have multiple record dates on the table and each day have note)
Query
SELECT
min(tm.create_date) 'Created Date'
, max(tm.timeslip_date) 'Last Bill Date'
, cases.case_sk
, cases.case_number
, cases.closed_ind
, cases.atty2_sk
, vc.atty2_name 'Business Leader'
, em.smtp_reply_to 'Business Leader Email'
, cases.atty1_sk
, vc.atty1_name 'Assign Attorney'
, tm.detail_notes
FROM dbo.cases
LEFT JOIN dbo.vcases vc ON cases.case_sk = vc.case_sk
LEFT JOIN dbo.employee em ON cases.atty2_sk = em.employee_sk
LEFT JOIN dbo.timeslips tm ON cases.case_sk = tm.case_sk
WHERE
cases.case_number = '0130751-KMG'
AND tm.timeslip_date <= DATEADD(day, -90, GETDATE())
AND cases.closed_ind = 'O'
GROUP BY
cases.case_sk
, cases.case_number
, cases.closed_ind
, cases.atty2_sk
, vc.atty2_name
, em.smtp_reply_to
, cases.atty1_sk
, vc.atty1_name
, tm.detail_notes
Error
The text, next, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
I would really appreciate any help on this. Lastly, can anyone confirmed my logic, I am trying to get cases with no tm.timeslip_date
for the last 90 days. I should get that with tm.timeslip_date <= DATEADD(day, -90, GETDATE())
this logic, right.
Thank you so much