retrieving the longest field length in a table

  • Hi. Can someone tell me how I could get the longest actual field length in a table. For example, say I have a NAME field in a table. I want to see the row that has the longest value in that NAME field in that table.

    Juanita

     

  • SELECT

    MAX(LEN([Name]))

    FROM

    ******************
    Dinakar Nethi
    Life is short. Enjoy it.
    ******************

  • To retrieve the entire row which has longest name:

    SELECT *

    FROM YourTable YT

    WHERE LEN(YT.Column_1) = (SELECT MAX(LEN(Column_1)) FROM YourTable)

    It will display all matching rows, if several rows have the same length of Column_1 entry. Should you need only one row each time, you have to limit it with SELECT TOP 1 *.

    HTH, Vladan

  • Thanks so much !!! Both options work great. Exactly what I needed!!!

     

    Juanita

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply