declare @sql varchar(8000), @tbl varchar(255), @col varchar(255), @data varchar(50)
set @data = 'SEARCH_TERM_WE_ARE_LOOKING_FOR'
declare cur_tbl cursor for
select a.name, b.name from sysobjects a, syscolumns b, systypes c where a.id = b.id and a.type = 'U' and c.xtype = b.xtype and c.name in ( 'varchar',
'nvarchar', 'text', 'ntext' )
open cur_tbl
fetch next from cur_tbl into @tbl, @col
while @@fetch_status = 0
begin
set @sql = '
if exists (select * from [' + @tbl + '] where convert( varchar(255), [' + @col + '] ) like ''%' + @data + '%'')
select tbl=''' + @tbl + ''', col=''' + @col + ''', [' + @col + '], * from [' + @tbl + '] where convert( varchar(255), [' + @col + '] ) like ''%' + @data
+ '%''
'
exec(@sql)
fetch next from cur_tbl into @tbl, @col
end
close cur_tbl
deallocate cur_tbl
|