yeah.. okay, why?This would be dynamic SQL unless there is some new stuff in 2005 for this (I'm not up-to-date)dynamic sql is not ideal...but I havent done this in a while...Declare @tableName varchar(100), @sqlStr varchar(8000), @position intSet @tableName = 'authors'Drop Table #TempTableCreate Table #TempTable ( ColumnName varchar(1000) not null, MaxVal varchar(1000) null, NullCnt bigint null, DistinctCnt bigint null)Set @position = 1While exists(Select * From pubs.Information_Schema.Columns Where Table_Name = @tableName and Ordinal_Position = @position)Begin Set @sqlStr = null Select @sqlStr = 'Select ' + 'ColumnName = ''' + COLUMN_NAME + ''', ' + 'MaxVal = convert(varchar,max(' + COLUMN_NAME + ')), ' + 'NullCnt = sum(case when ' + COLUMN_NAME + ' is null then 1 else 0 end), ' + 'DistinctCnt = count(distinct ' + COLUMN_NAME + ') ' + 'From pubs.dbo.' + @tableName + ' ' From pubs.Information_Schema.Columns Where Table_Name = @tableName and Ordinal_Position = @position and Data_Type <> 'bit' if (@sqlStr is not null) Begin Insert Into #TempTable exec (@sqlStr) End Select @Position = @Position + 1EndSelect * From #TempTableCorey
Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."