Azure SQL Server 2016 - I'm having trouble with the syntax to combine TOP
, MAX
and DATALENGTH
to get a list of the Top 50 records from a table by DATALENGTH
of a specific field.
The field I need to do the DATALENGTH
on is called Text
. I don't actually want the Text
field returned in the results - What I want returned are fields called CaptureId
and TaskSourceId
from the 50 records with the largest DATALENGTH
in the Text
field, as well as the DATALENGTH
amount.
I tried this, but it did not work, with an error about CaptureId not being contained in an aggregate function or GROUP BY clause.
SELECT TOP 50
CaptureId,
TaskSourceId,
MAX(DATALENGTH([Text]))
FROM
Data.Capture
Can someone please help me correct this query?