i am trying to view the lengthiest posts on stackoverflow using:

i am doing:

select max(body) from posts;​

and it returns:

You'd be looking to static link (as opposed to dynamically link)

I'm not sure how many of the MS redistributables statically link in.

anyone know what i am doing wrong?

+2  A: 

How about something like

select top 10 len(body) from posts order by len(body) desc​
+3  A: 
select top 10 body from posts order by len(body) desc;
Leom Burke
+1  A: 
Select Top 10 Title, Len(Body) As BodyLength
From Posts
Order By Len(Body) Desc
+1  A: 

It looks like you want something like:

select top 10 body from posts order by len(body) desc

Jerry Coffin
+3  A: 

The max function returns the maximum value of an expression. What (I think) you want is a combination of top and len(body).

select top 10 len(body), Id as [Post Link] 
from posts
order by len(body) desc
Bill the Lizard
bill you are the man. no wonder they call you the lizard
+2  A: 

max(body) Doesnt return the longest message but the last message if you sort alphabetically. in our case it starts with

You'd be looking ...

+2  A: 

MAX is an aggregate function. When dealing with a numeric column data type, it will return the highest value. For character columns, MAX finds the highest value in the collating sequence. Either way, it will only return one value per group - if no groups are specified, it will only return one value.

That leaves you with needing to get the length of the body so you can order the results - you have two options:

  • LEN returns the number of characters, rather than the number of bytes, of the given string expression, excluding trailing blanks.
  • DATALENGTH returns the number of bytes used to represent any expression. DATALENGTH is especially useful with varchar, varbinary, text, image, nvarchar, and ntext data types because these data types can store variable-length data. The DATALENGTH of NULL is NULL.

So you'd want to use the following query:

  SELECT TOP 10 p.body
OMG Ponies