SQL Server Performance

How to get max length of char in the field.

Discussion in 'General Developer Questions' started by snow12, Apr 29, 2008.

  1. snow12 New Member

    I have a field colum whose type is varchar. How to find which row has the max length of character in this field column?
  2. Luis Martin Moderator

    select max(LEN(charfield)) as maxchar from yourtable
  3. snow12 New Member

    Hi, Louis
    Thanks for the help. I got maxchar: 500, but I would like to know which row has this max character field. How to do it?
  4. Luis Martin Moderator

    Try something like:
    SELECT max(len(charfield)) as maxchar ,
    (SELECT COUNT(*) FROM yourtable) AS rownumber
    from yourtable
  5. Madhivanan Moderator

    Also try
    select * from yourtable where LEN(charfield)=(select max(LEN(charfield)) as maxchar from yourtable)

Share This Page