Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 determine longest field length

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-01 : 07:59:10
John writes "How to get the count value of the longest field length in a specified column, or sorting the records in order of the longest field length. Thanks for your help, greaty appreciated"

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2002-07-01 : 08:08:15
Lookup DATALENGTH in BOL

Here's an example:
USE pubs
GO
SELECT length = DATALENGTH(pub_name), pub_name
FROM publishers
ORDER BY length DESC
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-07-01 : 08:11:48
select max(len(name)) from customer

as long as name is NOT a TEXT field....len doesn't work with TEXT fields.

select len(rtrim(name)) from customer
order by len(rtrim(name)) desc


remember that blank spaces count as part of the length of a column, if the type is just CHAR and not VARCHAR....ergo the "rtim"

HTH

Go to Top of Page
   

- Advertisement -