Hi all,
Hi all, I am trying to get a list of all columns in a table (done) and then find the maximum length of the field that is used. For example if I have a table called Foo and there is a varchar field called Bar. I want to know what the allowed length of that column is and what actual space is being used by the string. So say bar has just values ‘Y’ in it, output should look like. (I can format the output..Just need help getting the data. )
Table Foo - Bar - > SQL Length = 500 - Actual max length used = 1
Hi all, I am trying to get a list of all columns in a table (done) and then find the maximum length of the field that is used. For example if I have a table called Foo and there is a varchar field called Bar. I want to know what the allowed length of that column is and what actual space is being used by the string. So say bar has just values ‘Y’ in it, output should look like. (I can format the output..Just need help getting the data. )
Table Foo - Bar - > SQL Length = 500 - Actual max length used = 1
Code:
select
(syscolumns.length) as [Length], (select MAX(LEN( syscolumns.name))from Foo ) AS MaxColLengthUsed, -- this bit not work
syscolumns.name as [Column],
syscolumns.xusertype as [Type],
sysobjects.xtype as [Objtype],*
from
sysobjects, syscolumns
where sysobjects.id = syscolumns.id
and sysobjects.xtype = 'u'
and sysobjects.name = 'Foo'
order by syscolumns.name
[/code
Age is a consequence of experience