
March 9th, 2012, 07:17 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 608
  
Time spent in forums: 4 Days 49 m 10 sec
Reputation Power: 14
|
|
|
You're just looking for some way to automatically generate the query, right?
declare @sql varchar(max)
select @sql = @sql + ', max(length(' + column_name + ')) as Max' + column_name
from information_schema.columns
where table_name = 'YourTable'
-- untested, but needed to only target text columns:
-- and type in ('varchar', 'nvarchar' etc...)
select @sql = 'select ' + substring(@sql, 1) /* take out first comma */ + ' from YourTable'
sp_ExecuteSQL @sql
|