create proc sp_ColumnHelp @colname nvarchar(776) = NULL, -- object name we're after @colvalue varchar(255) = NULL -- column value we're after as -- PRELIMINARY set nocount on declare @dbname sysname declare @table nvarchar(776) declare @tableid int -- INFO FOR EACH COLUMN print ' ' select Table_Name = o.name, Column_name = c.name, Table_ID = c.id into #tempTables from syscolumns c inner join sysobjects o on c.id= o.id where c.name = @colname order by o.name,c.name select * from #tempTables if @colvalue is not NULL begin DECLARE tables_cursor CURSOR FOR SELECT table_name, table_id FROM #tempTables OPEN tables_cursor FETCH NEXT FROM tables_cursor INTO @table, @tableid WHILE @@FETCH_STATUS = 0 BEGIN exec(' SELECT "There are", count(*), "record(s) in table' + @table + '"' + ' FROM ' +@table + ' where ' + @Colname +'="'+ @colvalue +'"' ) FETCH NEXT FROM tables_cursor INTO @table, @tableid END CLOSE tables_cursor DEALLOCATE tables_cursor end drop table #tempTables return (0) --sp_ColumnHelp coid, 233 set nocount off