Skip to content
Advertisement

How do I get the lates tm.detail_notes ( tm.detail_notes for max(tm.timeslip_date))?

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

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

Advertisement

Answer

Without knowing more tm.detail_notes appears to be a text column which is one of the special columns of large, open-ended data types. See ntext, text, and image (Transact-SQL). These fields cannot be used in columns expressions of an aggregate query with GROUP BY.

To incorporate the text field with your aggregation, consider using two related CTEs for a unit level and aggregate level join. Final query will then bind the text column to aggregation joined at the Last Bill Date.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement